Sridhar Raj Sampath Kumar Archive

Coloring console logs in nodejs

Colored console log messages can be helpful in determining the progress of the application when we boot it. Since the application will be started from the console, displaying green for the infos, Red for the error will be helpful in diagnosing on which stage the application has failed.

I use SindreSorhus's chalk because it is simple, doesn't extend String.prototype and used by ~4500 other modules.

Let's get to the code. First, we need to install chalk.

To demonstrate red, we are going to print stack trace of an error.

For my new posts, early access to my side projects, and more, get on my private email list, here:subscribe