On this page

ts-node, tsx and Runtime Tools

Enrico Hochkoeppler Profile

By Enrico Hochkoeppler

Web Developer & TutoriaLibre Founder

This lesson focuses on one of the most practical parts of the TypeScript ecosystem: runtime tools that let you execute TypeScript directly, without manually running tsc or generating .js output.

These tools dramatically improve developer experience, especially during prototyping, scripting, and backend development.

We’ll explore:


Why Runtime Tools Matter​

By default, TypeScript requires a two‑step workflow:

  1. Compile .ts → .js using tsc
  2. Run the generated .js with Node.js

This is fine for production builds, but slow and clunky for:

Runtime tools remove the friction by letting you run TypeScript directly, with zero build step.


ts-node​

ts-node is the classic tool for running TypeScript at runtime.

Install​


npm install --save-dev ts-node typescript

Run a file​


npx ts-node src/index.ts

How it works​

Pros​

Cons​


tsx (the modern favorite)​

tsx is a newer, faster runtime powered by esbuild.

Install​


npm install --save-dev tsx

Run a file​


npx tsx src/index.ts

How it works​

Pros​

Cons​

When to use​


ts-node vs tsx: Quick Comparison​

Featurets-nodetsxSpeedMediumVery fastType checkingYes (optional)NoConfig requiredYesNoBest forCLIs, REPL, scriptsDev servers, prototypingUsesTypeScript compileresbuild


Other Runtime Tools​

1. Bun​

Bun has built‑in TypeScript support:


bun run index.ts

2. Deno​

Deno runs TypeScript natively:


deno run index.ts

3. ts-node-dev​

A hot‑reload wrapper around ts-node:


npx ts-node-dev src/index.ts

Type Checking vs Transpiling​

Runtime tools fall into two categories:

1. Transpile‑only (fast)​

They skip type checking for speed.

You run tsc --noEmit separately if needed.

2. Full type‑checking (slower)​

They ensure correctness at runtime.

Recommended workflow​

During development:


tsx watch src/index.ts

During CI:


tsc --noEmit

This gives you speed and safety.


Using Runtime Tools in Real Projects​

Example: Running a Fastify server​


npx tsx src/server.ts

Example: Running a script​


npx ts-node scripts/generate.ts

Example: Hot reload​


npx tsx watch src/server.ts

Example: Type‑check only​


npx tsc --noEmit

This is the workflow used by many modern TypeScript backends.


Common Pitfalls​

1. Runtime tools ≠ production builds​

You should still build with:


tsc

or


esbuild

for production.

2. Missing type checking​

Tools like tsx don’t catch type errors.

Always run tsc --noEmit in CI.

3. ESM vs CommonJS confusion​

Runtime tools often default to ESM.

Make sure your tsconfig.json matches your environment.


Summary​

In this lesson, you learned how to run TypeScript without compiling:

1. ts-node​

2. tsx​

3. Bun & Deno​

4. Best practices​

Runtime tools dramatically improve the TypeScript developer experience—especially when prototyping or building backend services.

Found this helpful? Share the knowledge...

... or support this project to keep it alive!

Buy Me a Coffee

Previous

Tooling, Build Systems & Ecosystem

Next

Bundlers & Frameworks