TypeScript execution environment and REPL for node. Works with
typescript@>=1.5.
npm install -g ts-node
# Install a TypeScript compiler (requires `typescript` by default).
npm install -g typescript- Execute TypeScript files with node
- Interactive REPL
- Execute (and print) TypeScript through the CLI
- Uses source maps
- Loads from
tsconfig.json
# Execute a script as you world normally with `node`.
ts-node script.ts
# Starts the TypeScript REPL.
ts-node
# Execute code snippets with TypeScript.
ts-node -e 'console.log("Hello, world!")'
# Execute and print code snippets with TypeScript.
ts-node -p '"Hello, world!"'Mocha:
mocha test.ts --require ts-node/register src/**/*.spec.ts
Tape:
ts-node node_modules/tape/bin/tape src/**/*.spec.ts
Typescript Node automatically loads tsconfig.json options and referenced files from the current directory using tsconfig.
You can set options by passing them in before the script.
ts-node --compiler ntypescript --project src --ignoreWarnings 2304 hello-world.ts- project Location to resolve
tsconfig.jsonfrom. - compiler Use a custom, require-able TypeScript compiler compatible with
typescript@>=1.5.0-alpha. - ignoreWarnings Set an array of TypeScript diagnostic codes to ignore.
- disableWarnings Ignore all TypeScript errors.
require('ts-node').register({ /* options */ })
// Or using the shortcut file.
require('ts-node/register')MIT
