colors.js icon indicating copy to clipboard operation
colors.js copied to clipboard

Does not work in a forked child process

Open nodesocket opened this issue 7 years ago • 1 comments

When a child processes is forked:

const cp = require('child_process');
cp.fork('./worker.js');
// worker.js
const colors = require('colors');
console.log(colors.red('this should be red...'));

Colors does not seem to work inside the forked child (i.e. worker.js).

nodesocket avatar Mar 27 '19 01:03 nodesocket

I just ran into something similar running a script in a cron job. It turns out that the package tries to detect whether the console supports colors, and you can override it but it's not documented. This worked for me:

const colors = require('colors');
colors.enable();

It looks like you can also set process.env.FORCE_COLOR=1 or use any one of a bunch of flags to force colors to work.

mrjacobbloom avatar May 13 '19 17:05 mrjacobbloom