NODEJS Contents

Express + TypeScript: Minimal Setup

A production Express setup is mostly about TypeScript, environment configuration, safe defaults, and a clean module layout—not about adding more dependencies.

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 + listen
  • src/app.ts - express app composition
  • src/routes - route modules
  • src/middleware - shared middleware
  • src/services - domain/business logic
  • src/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.