ts-node(1)
execute JavaScript and TypeScript code
Summary
ts-node runs TypeScript (and JavaScript) code directly with Node.js, compiling on the fly so you do not have to run a separate tsc build step first. Use it to execute a .ts file, evaluate a snippet inline, or open an interactive TypeScript REPL during development. It reads your tsconfig.json by default for compiler settings.
Description
TS-NODE
NAME
ts-node - execute JavaScript and TypeScript code
SYNOPSIS
ts-node [options] [-e script] [arguments]
DESCRIPTION
Runs the given
script, either in a file or inlined with the -e
switch, using Node.js or TypeScript.
-e, --eval [code]
Evaluate code
-p, --print
Print result of ‘--eval‘
-r, --require [path]
Require a node module before execution
-i, --interactive
Opens the REPL even if stdin does not appear to be a terminal
-h, --help
Print CLI usage
-v, --version
Print module version information
-s, --script-mode
Use cwd from <script.ts> instead of current directory
-T, --transpile-only
Use TypeScript’s faster ‘transpileModule‘
-H, --compiler-host
Use TypeScript’s compiler host API
-I, --ignore [pattern]
Override the path patterns to skip compilation
-P, --project [path]
Path to TypeScript JSON project file
-C, --compiler [name]
Specify a custom TypeScript compiler
|
-D, --ignore-diagnostics [code] Ignore TypeScript warnings by diagnostic code |
-O, --compiler-options [opts]
JSON object to merge with compiler options
|
--dir |
Specify working directory for config resolution |
--scope
Scope compiler to files within ‘cwd‘ only
--files
Load ‘files‘, ‘include‘ and ‘exclude‘ from ‘tsconfig.json‘ on startup
--pretty
Use pretty diagnostic formatter (usually enabled by default)
--skip-project
Skip reading ‘tsconfig.json‘
--skip-ignore
Skip ‘--ignore‘ checks
--prefer-ts-exts
Prefer importing TypeScript files over JavaScript files
--log-error
Logs TypeScript errors to stderr instead of throwing exceptions
Examples
ts-node script.ts
Compile and run a TypeScript file directly, no separate build step needed.
ts-node -e 'console.log(1 + 2)'
Evaluate a snippet of code inline with -e (--eval) instead of from a file.
ts-node -T script.ts
Run with --transpile-only for faster startup that skips type checking.
ts-node -P ./tsconfig.build.json script.ts
Use a specific TypeScript project file with -P (--project) for compiler options.