Skip to content

node.js: Console Colors 101

Móricz Gergő on April 05, 2017

We've all seen a module or a node.js application that has changed the color of the command prompt font. Heck, even npm changes the color of it's te... [Read Full]
markdown guide

I've found it's useful to honour (or should that be honor?) the NODE_DISABLE_COLORS environment variable so users can easily disable this feature if it's not wanted. Documentation here.

I simply define colours as:

var red = process.env.NODE_DISABLE_COLORS ? '' : '\x1b[31m';
var green = process.env.NODE_DISABLE_COLORS ? '' : '\x1b[32m';
var normal = process.env.NODE_DISABLE_COLORS ? '' : '\x1b[0m';



So it uses ANSI sequences? Sweet. Does it support more than just the color codes?


Yes! There is an article about text positioning coming out very soon.

code of conduct - report abuse