TypeScript brings type safety to your Express API. Here is how to configure it properly with path aliases, strict mode, and ts-node.

Abdur Razzak
Full-Stack Web Developer
Install typescript, @types/node, and ts-node-dev as dev dependencies. Create a tsconfig.json with target ES2020 or later, module CommonJS, strict true, and outDir pointing to a dist folder.
Configure paths in tsconfig.json to replace relative imports like ../../../utils with @/utils. Install tsconfig-paths or use module-alias at runtime. This makes imports readable and removes the pain of refactoring file locations.
Define a typed config object that reads from process.env and throws at startup if required variables are missing. This catches misconfigured deployments immediately rather than surfacing errors at runtime when a specific feature is used.
Run tsc to compile TypeScript to JavaScript in the dist folder. Your production server runs node dist/server.js — no ts-node needed. This keeps the production footprint small and startup times fast.