Skip to content

CLI usage ​

Use the tsx command to run TypeScript and JavaScript with Node.js. The examples on this page assume tsx is installed in your project and run from the project directory.

Swap node for tsx ​

Use npx tsx in place of node to run a script. For example, save the following file in your project directory:

file.ts

ts
console.log(process.argv.slice(2))

Run it with two script arguments:

sh
npx tsx ./file.ts --name Ada

It prints:

text
[ '--name', 'Ada' ]

tsx runs your code in Node.js and accepts Node.js command-line flags, subject to the installed Node.js version's capabilities.

Flag & arguments positioning ​

Place tsx and Node.js flags before the script path. Place arguments intended for your script after the path:

The command has this form:

text
npx tsx [runtime flags] ./file.ts [script arguments]

Run the file.ts example above with a Node.js flag and two script arguments:

sh
npx tsx --no-warnings ./file.ts --name Ada

It prints:

text
[ '--name', 'Ada' ]

The --no-warnings flag configures Node.js. The script receives --name and Ada as arguments.

tsx options ​

OptionTypeDefaultPurpose
--tsconfig <path>StringNot set; detect from the working directoryUse a custom TypeScript configuration.
--no-cacheBooleanfalseDisable caching of transformed code.
--help, -hBooleanfalseShow tsx and Node.js CLI help.
--version, -vBooleanfalseShow the tsx and Node.js versions.

The script path is an optional string. With a path, tsx executes that file and forwards the script's exit status. Without a path or another execution option, tsx opens the REPL below. Script arguments are strings passed after the path and are available through process.argv.

Use tsx watch to rerun a script when its files change.

TypeScript REPL ​

Run npx tsx without a script path to open an interactive TypeScript prompt, also called a REPL:

sh
npx tsx

At the prompt, enter each line and press Return:

ts
const message: string = 'Hello, TypeScript!'
message.toUpperCase()

Output from the second expression:

text
'HELLO, TYPESCRIPT!'

Press Ctrl+D to exit. See the Node.js REPL documentation for prompt commands and other interactive features.

Test runner ​

Use Node.js's --test flag with tsx to run TypeScript tests. See Testing for a complete example and discovery behavior.