Skip to content

Premium sponsors

Node.js enhancement

Swap node for tsx

tsx is a drop-in replacement for node, meaning you can use it the exact same way (supports all command-line flags).

If you have an existing node command, simply substitute it with tsx.

sh
node --no-warnings --env-file=.env ./file.js

sh
tsx --no-warnings --env-file=.env ./file.js

Node.js version matters

Under the hood, tsx calls node. This means the Node.js features supported in tsx depend on the Node.js version you have installed.

Flag & arguments positioning

Just like with node, correctly positioning flags and arguments is important when using tsx.

Place tsx flags immediately after tsx, and place flags and arguments for your script after the script path.

sh
tsx [tsx flags] ./file.ts [flags & arguments for file.ts]

TypeScript REPL

tsx extends the Node.js REPL to support TypeScript, allowing interactive coding sessions directly in TypeScript.

sh
tsx

What is the Node.js REPL?

The Node.js REPL is an interactive prompt that immediately executes input code, ideal for learning and experimenting. tsx enhances this tool by adding TypeScript support.

Test runner

tsx enhances the Node.js built-in test runner with TypeScript support. You can use it the same way:

sh
tsx --test

It will automatically recognize test files with TypeScript extensions:

  • **/*.test.?[cm][jt]s
  • **/*-test.?[cm][jt]s
  • **/*_test.?[cm][jt]s
  • **/test-*.?[cm][jt]s
  • **/test.?[cm][jt]s
  • **/test/**/*.?[cm][jt]s