Skip to content

Express Template ​

The Express template provides a TypeScript-based backend using the Express.js framework. It includes pre-configured error handling, platform integration utilities, and a structured approach to building REST APIs with full TypeScript type safety.

Template Structure ​

src/
├── index.ts            # Application entry point with route definitions
├── lib/
│   ├── index.ts        # Package exports
│   ├── app.ts          # Express app setup and server start
│   ├── env.ts          # Environment variable validation
│   ├── errors.ts       # Custom error classes and handlers
│   ├── utils.ts        # Platform API utilities
│   └── services/       # Business logic and API service wrappers

Dependencies ​

The template uses the following key packages (defined in package.json):

  • express - Web framework for building REST APIs
  • typescript - Type-safe JavaScript superset
  • esbuild - Fast TypeScript/JavaScript bundler
  • dotenv - Environment variable management
  • nodemon - Development server with auto-restart
  • concurrently - Run multiple npm scripts simultaneously

Setup Instructions ​

1. Install Dependencies ​

bash
npm install

2. Configure Environment Variables ​

Create a .env file in the project root with the required platform configuration. See Creating Your First Application for details on obtaining these values.

Development Workflow ​

Running the Development Server ​

bash
npm start

This command uses concurrently to run two processes simultaneously:

  1. Build watcher (npm run dev:build) - Watches TypeScript files and rebuilds on changes
  2. Server (npm run dev:start) - Runs the built JavaScript with nodemon for auto-restart

The server will start on http://localhost:5000 (configurable via APP_PORT environment variable).

Hot Reload ​

The development setup provides automatic reloading:

  • esbuild watches for TypeScript changes and rebuilds instantly
  • nodemon detects changes to the built JavaScript files and restarts the server
  • Changes to source files trigger a rebuild → restart cycle automatically

Building for Production ​

bash
npm run build

This creates an optimized bundle in the dist/ directory using esbuild with:

  • Module bundling (all dependencies included)
  • Node.js platform target
  • ESM output format
  • External packages marked (not bundled)

Static File Serving ​

The template serves frontend static files in production mode:

app.ts
ts
if (isProd) {
  console.log("Serving static files from public/");
  app.use(express.static("public"));
  app.get(/.*/, (_req, res) => {
    res.sendFile("index.html", { root: "public/" });
  });
}

This catch-all route ensures the frontend handles client-side routing.

Platform Integration ​

The template includes utilities in lib/utils.ts for interacting with the platform gateway. For detailed information on authentication and API access patterns, see:

Next Steps ​