Skip to content

Latest commit

 

History

History
50 lines (32 loc) · 969 Bytes

node-cli.md

File metadata and controls

50 lines (32 loc) · 969 Bytes

Node.js CLI

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

:::

Custom tsconfig.json path

To specify a custom path to tsconfig.json, use an environment variable:

TSX_TSCONFIG_PATH=./path/to/tsconfig.custom.json node --import tsx ./file.ts

Binaries

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

Advanced usage

CommonJS mode only

To use tsx for CommonJS files only:

node --require tsx/cjs ./file.ts

Module mode only

To use tsx for Module files only:

node --import tsx/esm ./file.ts