diff --git a/README.md b/README.md index b11a961e0..d35d1ac32 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,11 @@ ts-node -p '"Hello, world!"' # Pipe scripts to execute with TypeScript. echo "console.log('Hello, world!')" | ts-node + +# Passing NODE_OPTIONS to the underlying process using TS_NODE_OPTIONS. +# All `TS_NODE_*` environment variables will be passed as `NODE_*` environment +# variables to your code. +TS_NODE_ENV="--inspect-brk" ts-node ``` ![TypeScript REPL](https://github.com/TypeStrong/ts-node/raw/master/screenshot.png) diff --git a/src/bin.ts b/src/bin.ts index 697dcbb60..133c602e3 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -36,6 +36,17 @@ v8flags(function (err, v8flags) { '--expose-http2' ]) + const env: { [key: string]: string | undefined } = {} + + for (const key of Object.keys(process.env)) { + const val = process.env[key] + if (key.substring(0, 8) === 'TS_NODE_') { + env[key.substring(3)] = val + } else { + env[key] = val + } + } + for (let i = 0; i < argv.length; i++) { const arg = argv[i] const flag = arg.split('=', 1)[0] @@ -62,6 +73,7 @@ v8flags(function (err, v8flags) { // // See: https://nodejs.org/api/child_process.html#child_process_options_detached detached: true, + env, stdio: 'inherit' } )