Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS_NODE_OPTIONS #476

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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'
}
)
Expand Down