Setting Up an Express + TypeScript Project
Before writing any routes, get a minimal Express + TypeScript project compiling and running.
Install dependencies
npm init -y
npm install express zod
npm install -D typescript @types/express @types/node tsx
npx tsc --init
express and zod are runtime dependencies, your server actually needs them once it's running. typescript and @types/express/@types/node are dev-only, they exist purely to type-check your code before it ships. tsx runs .ts files directly during development without a separate build step.
Key tsconfig.json options
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"outDir": "dist"
}
}
"strict": true turns on every strict type-checking flag at once (including the unknown-forcing narrowing rules from the last course), it's the setting that makes TypeScript actually catch bugs instead of just documenting types. Leave it on for anything beyond a throwaway script.
A minimal server
The leading underscore in _req is a convention (not a language feature) for "this parameter is required by the function signature but isn't used in the body," it keeps an unused-parameter lint rule quiet without disabling the check entirely.
TIP
Add "dev": "tsx watch src/index.ts" and "build": "tsc" scripts to package.json, tsx watch re-runs the server on every save during development, tsc produces the compiled dist/ folder you'd actually deploy.