Marak / colors.js

get colors in your node.js console
https://github.com/Marak/colors.js
Other
5.16k stars 446 forks source link

Does not work in a forked child process #253

Open nodesocket opened 5 years ago

nodesocket commented 5 years ago

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).

mrjacobbloom commented 5 years ago

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.