Skip to content

Commit f851b00

Browse files
kristofkalocsaiQix-
andauthoredOct 13, 2021
adds README section regarding usage in child procs (#850)
* 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 <[email protected]> Co-authored-by: Qix <[email protected]>
1 parent d177f2b commit f851b00

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎README.md

+21
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,27 @@ if (debug.enabled) {
351351
You can also manually toggle this property to force the debug instance to be
352352
enabled or disabled.
353353

354+
## Usage in child processes
355+
356+
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.
357+
For example:
358+
359+
```javascript
360+
worker = fork(WORKER_WRAP_PATH, [workerPath], {
361+
stdio: [
362+
/* stdin: */ 0,
363+
/* stdout: */ 'pipe',
364+
/* stderr: */ 'pipe',
365+
'ipc',
366+
],
367+
env: Object.assign({}, process.env, {
368+
DEBUG_COLORS: 1 // without this settings, colors won't be shown
369+
}),
370+
});
371+
372+
worker.stderr.pipe(process.stderr, { end: false });
373+
```
374+
354375

355376
## Authors
356377

0 commit comments

Comments
 (0)
Please sign in to comment.