Express + TypeScript: Minimal Setup
On this page
TypeScript-First Setup
In production, TypeScript is a safety layer that reduces runtime surprises. Configure compilation, strictness, and source maps early so debugging and deployment behave consistently.
Minimal Production Structure
src/server.ts- bootstrap + listensrc/app.ts- express app compositionsrc/routes- route modulessrc/middleware- shared middlewaresrc/services- domain/business logicsrc/lib- utilities (logger, config, errors)
Bootstrapping Pattern
Keep app construction separate from the network listener so you can test the app without binding sockets and you can control shutdown in production.
import http from 'http';
import { createApp } from './app';
const app = createApp();
const server = http.createServer(app);
server.listen(process.env.PORT ? Number(process.env.PORT) : 3000);
Environment Safety
Fail fast on missing configuration. Do not rely on implicit defaults for secrets, database URLs, or CORS origins.