colors.js
colors.js copied to clipboard
Does not work in a forked child process
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).
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.