ts-node lets you run TypeScript files directly in Node.js without having to compile them first. You just run ts-node myfile.ts
and it works. Well, eventually - after it spends 3-5 seconds starting up because it's actually running the TypeScript compiler under the hood.
Here's the thing everyone gets wrong: ts-node isn't just a convenience tool, it's fundamentally different from the new hotness like TSX or Node.js native TypeScript support. Those tools just strip out your types and run the JavaScript. ts-node actually compiles your TypeScript with proper type checking, which means it'll catch your fuckups before they crash your program.
Why ts-node is Slow (And Why That Might Be OK)
ts-node hooks into Node.js's module loading system and runs the actual TypeScript compiler on every file it encounters. This is why it's slow - it's not just transforming your code, it's actually checking all your types, validating your imports, and making sure your decorators are set up correctly.
When you run ts-node server.ts
on a decent-sized project, here's what happens:
- TypeScript compiler boots up (2-3 seconds on my MacBook Pro, longer on CI)
- It loads and parses your tsconfig.json
- It discovers all your source files
- It type-checks everything it finds
- Finally it runs your actual code
This is why that "quick test script" takes 5 seconds to start when it should take 50ms. But here's what you get for that pain:
- Real type checking that catches errors before runtime
- Proper source maps that actually point to your TypeScript files
- Full support for decorators, enums, and other TypeScript-specific features
- A REPL that actually understands your types
The Competition That's Eating ts-node's Lunch
TSX came along and said "fuck type checking, let's just run the code fast." It uses esbuild to strip types in milliseconds instead of compiling them properly. For most development, this is totally fine - you run `tsc --noEmit` separately to check types, and tsx for actually running code.
Interestingly, one 2024 benchmark found that ts-node with nodemon is actually 3x faster than tsx on large projects. Performance varies wildly - I've seen tsx blow up on 50k line codebases while ts-node chugs along fine.
Node.js v22.6.0+ added native TypeScript support that's even more basic - it literally just removes type annotations and runs the result. No type checking, no fancy features, just raw speed. Started in v22.6.0 and improved in later versions.
The brutal truth is that for 80% of TypeScript development, you don't need ts-node's type checking at runtime. You just want to run your goddamn code without a build step.
When You Actually Need ts-node
You still want ts-node when:
- You have decorators everywhere (especially class-validator, TypeORM, NestJS stuff)
- You're debugging type errors and need accurate stack traces
- You're writing complex generic code that breaks when types are stripped
- You're too lazy to set up a separate type checking step
- You're working on tooling/build scripts where correctness matters more than speed
I've seen teams switch to tsx and then come crawling back to ts-node when their decorator-heavy NestJS app started throwing TypeError: Cannot read properties of undefined (reading 'metadata')
errors in production. Type stripping breaks more shit than people expect - especially when reflect-metadata gets confused.