Skip to content

Commit

Permalink
adds README section regarding usage in child procs (#850)
Browse files Browse the repository at this point in the history
* adds README section regarding usage in child procs

code example and original request copied from @aaarichter
should close #811

* Update README.md

Co-authored-by: Qix <Qix-@users.noreply.github.com>

Co-authored-by: Qix <Qix-@users.noreply.github.com>
  • Loading branch information
kristofkalocsai and Qix- authored Oct 13, 2021
1 parent d177f2b commit f851b00
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 `debug` 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 f851b00

Please # to comment.