From f851b00eb006d400e757dca33568773910365519 Mon Sep 17 00:00:00 2001 From: Kristof Kalocsai Date: Wed, 13 Oct 2021 21:14:14 +0200 Subject: [PATCH] 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 Co-authored-by: Qix --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 88dae35d..3b168838 100644 --- a/README.md +++ b/README.md @@ -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