Guide · Open source
How to use ts-node: run TypeScript on Node.js and in a REPL
Updated · written with AI from the project's own documentation and checked against our catalogue data
ts-node is an open-source (MIT licensed) TypeScript execution engine and REPL for Node.js. It compiles TypeScript to JavaScript as files load, so you can run a .ts script directly without a separate precompile step. This guide shows you how to install it, run scripts and code, use the REPL, and where its settings come from.
Quick start
- 1Check prerequisites. Confirm that Node.js and npm are installed on your machine.
- 2Install TypeScript and ts-node. Run npm install -D typescript and npm install -D ts-node in your project folder.
- 3Run a script. Execute a file with ts-node script.ts to compile and run it in one step.
- 4Try inline code. Use ts-node -e with a snippet, or ts-node -p -e to print a result.
- 5Start the REPL. Run ts-node with no arguments to open an interactive TypeScript REPL.
- 6Move settings into tsconfig.json. Put compiler and ts-node options in tsconfig.json so your scripts and commands share the same configuration.
Install ts-node with npm
You need Node.js and npm. Install TypeScript and ts-node locally in your project so the versions are recorded in package.json.
- Installing locally lets you control and share versions through package.json.
- ts-node resolves the compiler from the current working directory before checking relative to its own installation.
- Depending on your configuration you may also need tslib and @types/node.
npm install -D typescript
npm install -D ts-node
# Depending on configuration, you may also need these
npm install -D tslib @types/nodeRun a TypeScript script with ts-node
Pass a TypeScript file to ts-node to execute it. The README describes this as executing the script as node plus tsc. You can also run one-off code with the -e flag, or print the result with -p.
- ts-node script.ts runs a file.
- ts-node -e runs an inline snippet.
- ts-node -p -e prints the result of an expression.
- Piping code into ts-node also works.
# Execute a script as `node` + `tsc`.
ts-node script.ts
# Execute code with TypeScript.
ts-node -e 'console.log("Hello, world!")'
# Execute, and print, code with TypeScript.
ts-node -p -e '"Hello, world!"'
# Pipe scripts to execute with TypeScript.
echo 'console.log("Hello, world!")' | ts-nodeUse the TypeScript REPL
Run ts-node with no arguments to start an interactive TypeScript REPL inside Node.js. This is useful for quick experiments.
ts-nodeConfigure ts-node with tsconfig.json
ts-node reads tsconfig.json automatically, so you can put your options there and keep them out of the command line. The README recommends this approach for portability. Options can also be passed as CLI flags, and there is a list of TSConfig options such as project, skipProject and compilerOptions.
- Automatic tsconfig.json parsing is listed as a feature.
- Options set in tsconfig.json are the recommended way to configure ts-node.
- Typechecking is optional; transpileOnly is available if you want faster runs without type checks.
Use ts-node in a shebang script
You can make a TypeScript file executable with a shebang line. The README recommends putting options in tsconfig.json and omitting them from the shebang. Passing options in the shebang requires env -S on versions of env that support it.
#!/usr/bin/env ts-node
// ts-node options are read from tsconfig.json
console.log("Hello, world!")Know when not to use ts-node in production
The README lists ts-node as compatible with pre-compilation for production, but it does not present on-the-fly compilation as the production path. For production servers that should run precompiled JavaScript, compile with tsc and run the JavaScript output.
- Use it for scripts, local experiments and tooling.
- For production, precompiled JavaScript is the path the source points to.
- Check the Troubleshooting section of the README if you hit TSError, SyntaxError, ERR_REQUIRE_ESM or ERR_UNKNOWN_FILE_EXTENSION.
What people use it for
- Running a TypeScript script locally, such as a data cleanup or build helper.
- Testing a snippet or API idea in the TypeScript REPL inside Node.js.
- Running TypeScript with the same settings as your project by reading tsconfig.json.
- Integrating TypeScript execution with test runners or CLI tools, as the README describes.
Frequently asked questions
Is ts-node free to use?
ts-node is released under the MIT licence, as stated on its project page. Check the LICENSE file in the repository for the full terms.
What do I need before installing ts-node?
The source lists Node.js and npm as prerequisites. Install TypeScript and ts-node locally with npm install -D typescript and npm install -D ts-node.
How do I run a TypeScript file with ts-node?
Run ts-node script.ts in your terminal. ts-node compiles the TypeScript as it loads and executes it, so you do not need a separate compile step first.
Can I use ts-node in production?
The README says ts-node is compatible with pre-compilation but does not present on-the-fly compilation as the production path. For production servers, running precompiled JavaScript is the approach the source recommends.
What are the alternatives to ts-node?
The comparable projects listed for this item are tsx, Bun and Deno. ts-node is specific to Node.js, so pick Bun or Deno if you need a different runtime.
Why does ts-node show TSError or ERR_REQUIRE_ESM?
The README has a Troubleshooting section covering TSError, SyntaxError, ERR_REQUIRE_ESM and ERR_UNKNOWN_FILE_EXTENSION, plus missing types. Start there and check your tsconfig.json and module settings.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
ts-node suits developers who want to run TypeScript scripts, try code in a REPL, or share tsconfig.json settings with local tooling on Node.js. Beginners who have not set up Node.js and npm yet, or teams that need a non-Node runtime or a precompiled production server, should look at the alternatives listed, such as tsx, Bun or Deno, or compile with tsc.
Install options & downloads