Skip to content

Commit

Permalink
adds README section regarding usage in child procs
Browse files Browse the repository at this point in the history
code example and original request copied from @
aaarichter
debug-js#811
  • Loading branch information
kristofkalocsai committed Oct 3, 2021
1 parent d177f2b commit f786972
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,27 @@ if (debug.enabled) {
You can also manually toggle this property to force the debug instance to be
enabled or disabled.

## Usage in child processes

Due to the way chalk detects if the output is a TTY or not, colors are not shown in child processes when `stderr` is piped. A solution is to pass the `DEBUG_COLORS=1` environment variable to the child process.
For example:

```javascript
worker = fork(WORKER_WRAP_PATH, [workerPath], {
stdio: [
/* stdin: */ 0,
/* stdout: */ 'pipe',
/* stderr: */ 'pipe',
'ipc',
],
env: Object.assign({}, process.env, {
DEBUG_COLORS: 1 // without this settings, colors won't be shown
}),
});

worker.stderr.pipe(process.stderr, { end: false });
```


## Authors

Expand Down

0 comments on commit f786972

Please # to comment.