Skip to content

ts-node

Runs TypeScript files directly in Node.js, with a REPL, without a separate build step.

Stars
13.1k
Forks
548
Licence
MIT
Language
TypeScript
Last update
2.3 years ago
Type
Dev tool

No commits in over a year — check for forks or alternatives before adopting.

What it is

ts-node lets you run TypeScript code directly on Node.js. It compiles TypeScript to JavaScript on the fly as files load, so you do not need a separate precompile step to try a script. It also provides an interactive TypeScript REPL.

  • Run a TypeScript script with `ts-node script.ts`
  • Start an interactive TypeScript REPL by running `ts-node` with no arguments
  • Execute a one-line TypeScript snippet with `ts-node -e`
  • Use it with test runners such as Mocha or AVA, per the recipes section

Great for

  • Developers running TypeScript scripts or quick experiments locally
  • People who want a TypeScript REPL inside Node.js
  • Projects that use tsconfig.json and want the same settings when running scripts
  • Teams integrating TypeScript execution with test runners or CLI tools

Not ideal for

  • Production servers that should run precompiled JavaScript; the README notes ts-node is compatible with pre-compilation but does not present on-the-fly compilation as the production path
  • Beginners who have not yet set up Node.js and npm, since installation and configuration involve several concepts
  • Projects needing a non-Node runtime, because it is specific to Node.js
Step-by-step guide: how to use ts-nodeInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Node.js · npm

    Install locally in your project

    npm install -D typescript

    Install ts-node locally

    npm install -D ts-node
  2. 2

    Run it

    • Install TypeScript and ts-node locally with npm
    • Create a file named script.ts containing console.log("Hello, world!")
    • Run it with `ts-node script.ts`
    • Or run `ts-node` with no arguments to open the REPL
  3. 3

    Get the most out of it

    • Put options in tsconfig.json rather than the command line, which the README recommends for portability
    • Use `transpileOnly` to speed up execution when typechecking is not needed, per the Performance section
    • Use the shebang `#!/usr/bin/env -S ts-node` with care, since passing options in it depends on the env version
    • Integrate with test runners via the README recipes for Mocha, AVA, and others

Downloads

Strengths

  • Stack traces map back to the original TypeScript source through sourcemaps
  • Reads tsconfig.json automatically
  • Supports native ESM loading and optional typechecking

Trade-offs

  • Typechecking adds overhead, and the README includes a Performance section on skipping it
  • Module loading and ESM behavior can require configuration, and the README has a troubleshooting section for common errors such as ERR_REQUIRE_ESM
  • The README is truncated here, so some details of options and limits could not be verified

How it compares

ProjectStarsTypeLevelUpdatedBest for
ts-node (this)13.1kDev toolintermediate2.3 years agoDevelopers running TypeScript scripts or quick experiments locally
tsx12.2kCLIbeginner1 months agoDevelopers who already use Node.js and want to run TypeScript scripts quickly
deno109kAppbeginner8 days agoDevelopers who want to run TypeScript without a separate build setup
distributions13.9kDev toolintermediate8 days agoLinux users who want a Node.js version installed through their system package manager
ts-pattern15.2kLibrarybeginner23 days agoTypeScript developers who write many if/else or switch branches over tagged unions

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.