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:::
To specify a custom path to tsconfig.json, use an environment variable:
TSX_TSCONFIG_PATH=./path/to/tsconfig.custom.json node --import tsx ./file.tsIf 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-binaryTo use tsx for CommonJS files only:
node --require tsx/cjs ./file.tsTo use tsx for Module files only:
node --import tsx/esm ./file.ts