docs/dev-api/node-cli.md
To use the node command directly with tsx, pass it as a flag:
node --import tsx ./file.ts
::: details (Deprecated) Node.js v20.5.1 and below
Older Node.js versions use a deprecated API --loader instead of --import.
node --loader tsx ./file.ts
:::
tsconfig.json pathTo specify a custom path to tsconfig.json, use an environment variable:
TSX_TSCONFIG_PATH=./path/to/tsconfig.custom.json node --import tsx ./file.ts
If you don't have direct access to the node command, use the Node.js NODE_OPTIONS environment variable to pass in the flag:
NODE_OPTIONS='--import tsx' npx some-binary
To use tsx for CommonJS files only:
node --require tsx/cjs ./file.ts
To use tsx for Module files only:
node --import tsx/esm ./file.ts