Get Style & Color in Your Node.js Console

By Hemanta Sundaray on 2021-11-16

I always use the colors module to get style and color in the Node.js console while developing full-stack applications.


npm install colors


The following code snippet is an example of how we spin up a server using Express.

const express = require("express");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const colors = require("colors");


const connectDB = async () => {
  try {
    const conn = await mongoose.connect(process.env.MONGO_URI, {
      useNewUrlParser: true,
      useUnifiedTopology: true,

    console.log(`MongoDB connected: ${}}`);
  } catch (error) {
    console.error(`Error: ${error.message}`);


const app = express();


const PORT = 5000;

app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}`;

When I execute the file using the command node index.js, we will see that the message - Server listening on port 5000 - is logged to the console with a bright blue background and black text.

Color & Style

You can customise the color and style according to your own preferences. To find out more about the options available, check out the link here.

Join the Newsletter