Run TypeScript files in Node.js

Choose native type stripping, tsx, ts-node, or a compile-first workflow, and keep type checking separate from execution.

Best practices
Illustration accompanying a Node.js development guide

Recent Node.js releases can execute TypeScript that needs only type stripping. For broader TypeScript tooling support, use a runner such as tsx, or compile with tsc and run the generated JavaScript. Check the exact Node version before choosing a command.

Native execution on supported Node releases

// hello.ts
const name: string = 'Ada';
console.log(`Hello, ${name}`);

On a release with type stripping enabled by default:

node hello.ts

Type stripping first appeared in Node 22.6 behind --experimental-strip-types. It became enabled by default in Node 23.6 and 22.18, and was marked stable in Node 24.12 and 25.2. Earlier releases without this support need a runner or compilation.

Native execution removes erasable type syntax; it does not type-check the program. It also does not read tsconfig.json to implement path aliases, change the JavaScript target, or apply compiler transformations. TSX is not supported. Features that require emitted JavaScript, such as enums and parameter properties, need another approach. Older experimental transformation flags are not a durable solution: --experimental-transform-types was removed in Node 26.

Use import type for type-only imports. Native relative imports must name the file actually being loaded, such as ./helper.ts. Module format rules still apply: .mts is ESM, .cts is CommonJS, and .ts follows the relevant package/module rules.

Use a development runner

npm install --save-dev tsx typescript
npx tsx src/index.ts
npx tsx watch src/index.ts
npx tsc --noEmit

tsx handles execution and watch mode; tsc --noEmit performs type checking. A successful run is not evidence that the program passed a full type check. Transformation tools also differ in their support for decorators, compiler options, and module resolution, so check the features your project uses.

ts-node is another option:

npm install --save-dev ts-node typescript
npx ts-node src/index.ts

That command fits a compatible CommonJS configuration. ESM projects need the runner's documented ESM setup; installing the package alone does not make every module configuration work unchanged.

Compile before deployment

A compile-first workflow separates development tooling from the production runtime:

npx tsc --project tsconfig.json
node dist/index.js

This assumes the configuration emits the entry point to dist/index.js. Set outDir, module format, and input paths deliberately. Ensure generated import paths resolve in the emitted JavaScript; a source import ending in .ts needs a compatible build strategy, such as TypeScript's supported relative-extension rewriting configuration.

Install build dependencies in the build stage, then deploy the generated output and its runtime dependencies. Keep the Node and TypeScript versions consistent in development and CI.

Which approach should I choose? Native stripping is useful for supported, erasable syntax. A runner is convenient for local development. Compilation gives you an explicit JavaScript artifact and works with runtimes that cannot execute TypeScript directly.

See Node's TypeScript support, tsx, and TypeScript compiler options.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting