Node - spinningideas/resources GitHub Wiki
Process Management
cmd "/C TASKKILL /IM node.exe /F"
bash -c "pkill -f 'node.*server.js'"
Typescript in Node
As of 2026, Node.js (v22+) has stable, built-in TypeScript support via "type stripping". There are now three distinct approaches depending on project complexity.
Option 1: Native Node.js Type Stripping (Zero-Config)
Node.js v22+ can run .ts files directly by stripping type annotations at the text level and executing the remaining JavaScript. No build step or dependencies required.
- Docs: https://nodejs.org/en/learn/typescript/run-natively
- Run a file:
node app.ts - Limitations:
- Does not type-check - use
tsc --noEmitseparately for that. - Ignores
tsconfig.jsonentirely. - Only supports "erasable" TypeScript syntax. The following are not supported:
enum,namespace,parameter properties, decorators that require code generation, and path aliases.
- Does not type-check - use
- Best for: Scripts, small utilities, quick prototypes.
Option 2: tsx (Recommended for Development)
tsx is the industry-standard development runner in 2026. Powered by esbuild, it is significantly faster than the legacy ts-node, supports full tsconfig.json resolution, path aliases, decorators, and ESM.
- Docs: https://tsx.is/
- Install:
npm install -D tsx - Run a file:
npx tsx src/app.ts - Run with watch mode (dev server):
npx tsx watch src/app.ts - In
package.jsonscripts:{ "scripts": { "dev": "tsx watch src/index.ts", "typecheck": "tsc --noEmit" } } - Note: Like native stripping,
tsxdoes not type-check. Runtsc --noEmitin CI or as a separate script to catch type errors. - Best for: Production backends, complex apps, any project using path aliases or decorators.
ts-node is now considered legacy. Most projects have migrated to
tsx.
Option 3: tsc Build Pipeline (Production)
For production deployments, the canonical approach is to compile TypeScript to JavaScript using the TypeScript compiler (tsc) and then run the compiled output.
- Install TypeScript:
npm install -D typescript @types/node - Initialise tsconfig:
npx tsc --init - Compile:
npx tsc - Run compiled output:
node dist/index.js - In
package.jsonscripts:{ "scripts": { "build": "tsc", "start": "node dist/index.js", "dev": "tsx watch src/index.ts", "typecheck": "tsc --noEmit" } }
Recommended tsconfig.json (2026)
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"skipLibCheck": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"]
}
Comparison Summary
Native node |
tsx |
tsc build |
|
|---|---|---|---|
| Setup | Zero-config | Install tsx |
Install typescript |
| tsconfig.json | Ignored | Fully supported | Fully supported |
| Path aliases | ❌ | ✅ | ✅ |
| Decorators / enums | ❌ | ✅ | ✅ |
| Type checking | ❌ | ❌ (run tsc --noEmit) |
✅ |
| Best for | Scripts, utilities | Dev / production backends | Production deployments |
References
- https://nodejs.org/en/learn/typescript/run-natively - Official Node.js TypeScript docs
- https://tsx.is/ - tsx runner
- https://www.typescriptlang.org/tsconfig/ - tsconfig reference
- https://brianflove.com/2017/03/22/express-cors-typescript/ - Express + CORS + TypeScript (older reference)