Appearance
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 wrappersDependencies
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 install2. 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 startThis command uses concurrently to run two processes simultaneously:
- Build watcher (
npm run dev:build) - Watches TypeScript files and rebuilds on changes - 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 buildThis 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:
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:
- Authentication & Authorization - Understanding
fetchAsPrincipalvsfetchAsApp - Backend API Access Patterns - Making API calls to the platform gateway
- Error Handling Strategies - Handling upstream errors
Next Steps
- Review Backend API Access Patterns to learn how to make platform API calls
- Explore Framework Specific Backend Conventions for advanced Express patterns
- Check Demo Applications & Examples for complete working examples