Busca en todas las páginas de la documentación
Pick the right TypeScript toolchain per environment - tsx for fast dev and tests, tsc for production dist/, and avoid new ts-node adoption unless brownfield constraints require it.
{
"scripts": {
"dev": "node --watch --import tsx src/main.ts",
"build": "tsc -p tsconfig.json",
"start": "node dist/main.js",
"test": "node --import tsx --test src/**/*.test.ts"
},
"devDependencies": {
"typescript": "^5.6.0",
"tsx": "^4.0.0",
"@types/node": "^24.0.0"
}
}When to reach for this:
ts-node-dev or nodemon + ts-node stacks// src/main.ts
import { createServer } from 'node:http';
const port = Number(process.env.PORT ?? 3000);
createServer((_req, res) => {
res.end('ok');
}).# Development - no separate compile step
npm run dev
# Production pipeline
npm run build
npm run start// tsconfig.json - emit for production
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"sourceMap": true,
What this demonstrates:
tsx hooks Node's loader - transforms TS on the fly via esbuildtsc writes dist/main.js preserving ESM import specifiers with .js extensionsnode - no devDependency loader in the container--watch + tsx replaces nodemon for many servicesimport.meta, ideal for dev/test.dist/.build job.| Tool | Typecheck | Emit | Prod runtime | Speed |
|---|---|---|---|---|
| tsx | No (transpile only) | No | Dev/test only | Fast |
| tsc | Yes | Yes | Yes (dist/) | Moderate |
| ts-node | Partial | No | Legacy dev | Moderate |
| tsc + tsx | Split CI jobs | tsc | node dist | Best practice |
{
"scripts": {
"typecheck": "tsc --noEmit",
"dev": "node --watch --import tsx src/main.ts"
}
}Run typecheck in CI even when dev uses tsx - tsx alone skips type errors.
node dist/main.js in Docker CMD.tsc --noEmit in CI gate.tsc does not rewrite paths. Fix: NodeNext relative imports or tsc-alias post-step.tsc emits per module. Fix: align package.json "type" with emit.node --import tsx.| Alternative | Use When | Don't Use When |
|---|---|---|
SWC (@swc-node) | NestJS 11 SWC pipeline | Simple service needing minimal config |
| esbuild bundle | Single-file Lambda artifact | Multi-file Node server with dynamic import |
tsc --build project references | Large monorepos | Single-package API |
| Plain JS (no TS) | Tiny scripts | Teams standardized on TypeScript |
For running TS in prod - avoid. For dev/test - yes. Production should run compiled JS.
Yes - for typechecking and emitting dist/. tsx is not a typechecker.
node --watch --import tsx src/main.ts on Node 24.
Yes: node --import tsx --test src/**/*.test.ts.
Yes - multi-stage: npm ci, npm run build, copy dist/ + prod deps to runtime image.
Both supported - SWC faster compile; tsc stricter default for smaller services.
node --env-file=.env --import tsx src/main.ts loads env before TS executes.
node --inspect --import tsx src/main.ts - breakpoints map via source maps if enabled.
NodeNext requires .js specifiers in source so emit matches runtime.
Not officially, but new Node 24 projects should standardize on tsx for on-the-fly ESM.
skipLibCheck, project references, and incremental "incremental": true with .tsbuildinfo.
npm run typecheck then npm run test then npm run build - fail fast on types.
Stack versions: This page was written for Node.js 24.18.0 (Active LTS), npm 10+, TypeScript 5.6+, Express 5, Fastify 5, and NestJS 11.