Skip to content

ts-node, tsx, and Runtime Tools

  • Running TS without compiling

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:

  • how they work
  • when to use each
  • their trade‑offs
  • how they fit into modern TS workflows

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:

  • quick scripts
  • prototyping
  • REPL usage
  • local development
  • CLIs
  • server development with hot reload

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

  • loads TypeScript compiler in memory
  • transpiles files on the fly
  • executes them immediately

Pros

  • stable and widely used
  • supports full tsconfig.json
  • integrates with REPL (ts-node --swc for speed)
  • great for scripts and CLIs

Cons

  • slower than newer tools
  • cold start time can be noticeable
  • not ideal for large apps with many files

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

  • uses esbuild for ultra‑fast transpilation
  • supports ESM, JSX, and TS out of the box
  • no configuration required

Pros

  • extremely fast
  • zero config
  • perfect for dev servers
  • supports watch mode (tsx watch src/index.ts)

Cons

  • does not perform full type‑checking
  • relies on esbuild’s transpilation (not 100% identical to tsc)

When to use

  • local development
  • prototyping
  • running scripts
  • dev servers (e.g., Fastify, Express, Bun‑style workflows)

ts-node vs tsx: Quick Comparison

Feature ts-node tsx
Speed Medium Very fast
Type checking Yes (optional) No
Config required Yes No
Best for CLIs, REPL, scripts Dev servers, prototyping
Uses TypeScript compiler esbuild

Other Runtime Tools

1. Bun

Bun has built‑in TypeScript support:

bun run index.ts
  • extremely fast
  • supports JSX, TS, ESM
  • no config needed

2. Deno

Deno runs TypeScript natively:

deno run index.ts
  • no node_modules
  • secure by default
  • built‑in formatter, linter, test runner

3. ts-node-dev

A hot‑reload wrapper around ts-node:

npx ts-node-dev src/index.ts
  • auto‑restart on file changes
  • great for backend development

Type Checking vs Transpiling

Runtime tools fall into two categories:

1. Transpile‑only (fast)

  • tsx
  • Bun
  • esbuild‑based tools

They skip type checking for speed.

You run tsc --noEmit separately if needed.

2. Full type‑checking (slower)

  • ts-node
  • Deno (optional)

They ensure correctness at runtime.

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

  • classic runtime
  • supports full type checking
  • slower but reliable

2. tsx

  • modern, fast, zero‑config
  • ideal for dev servers and scripts
  • no type checking

3. Bun & Deno

  • built‑in TypeScript support
  • fast, batteries‑included runtimes

4. Best practices

  • use fast tools in development
  • use tsc --noEmit for type checking
  • use proper builds for production

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