ts-node lets you run TypeScript code directly without first turning it into JavaScript. This saves time and makes testing easier.
0
0
Running TypeScript with ts-node
Introduction
You want to quickly try out TypeScript code without setting up a build step.
You are writing small scripts or tools in TypeScript.
You want to run TypeScript files during development to see results fast.
You want to debug TypeScript code without compiling it first.
You want to run TypeScript code in a Node.js environment directly.
Syntax
Typescript
ts-node [options] <file.ts>
You run ts-node from the command line followed by the TypeScript file name.
Make sure you have ts-node installed globally or in your project.
Examples
Runs the TypeScript file named
script.ts directly.Typescript
ts-node script.ts
Runs
script.ts faster by skipping type checks.Typescript
ts-node --transpile-only script.ts
Runs
script.ts using settings from a specific tsconfig.json file.Typescript
ts-node --project tsconfig.json script.ts
Sample Program
This simple program prints a message to the console. You can run it with ts-node to see the output immediately.
Typescript
console.log('Hello from TypeScript!');
OutputSuccess
Important Notes
Install ts-node using npm install -g ts-node or npm install --save-dev ts-node.
ts-node uses your tsconfig.json file if present to understand TypeScript settings.
For faster runs during development, use the --transpile-only option to skip type checking.
Summary
ts-node runs TypeScript files directly without compiling first.
It is useful for quick testing, scripting, and development.
Use command line options to customize how ts-node runs your code.