Explain Colors Module in Node.js Last Updated : 30 Sep, 2021 Comments Improve Suggest changes Like Article Like Report The colors module is used to style and color the NodeJS console. It is a nice library for better interaction with your node.js project. Generally what we see is the simple text on the terminal but with this module, we can custom style according to our needs and the conventions i.e. we can change the color of the warning text to be red or we can underline the important keyword, etc. In this article, we are going to discuss the step-by-step approach to use this module. Step 1: Installation and Initialization: Open the terminal and create a node app because at the end we are going to work inside the NodeJS application npm init This command will ask for few configurations about the project and you can fill them easily, otherwise use the -y flag to set default configurations. Now Install the colors module npm install colors Create a javascript file (let's name it app.js) to write the entire code inside that. touch app.js Step 2: Import module in the application: Import the module with require keyword and with this, you are ready to use the colors module. const colors = require('colors'); Step 3: Start Working with Module: We can change the color of the text i.e black, red, green, yellow, etc and the background of the text area i.e. bgGreen, bgYellow, bgBlue, bgMagenta, etc. JavaScript const colors = require('colors'); console.log('Hello, GeeksforGeeks Learner'.red); console.log('Hello, GeeksforGeeks Learner'.bgMagenta); console.log('Hello, GeeksforGeeks Learner'.bgYellow.blue); Output: We can change the style of text i.e. underline, bold, strikethrough, dim, inverse, italic, etc. JavaScript const colors = require('colors'); console.log('Hello, GeeksforGeeks Learner'.underline); console.log('Hello, GeeksforGeeks Learner'.italic); console.log('Hello, GeeksforGeeks Learner'.bold); console.log('Hello, GeeksforGeeks Learner'.inverse); Output: We can create our custom styles with the setTheme method, it accepts an object and later we can use the properties in code.We can combine two or more properties by using an array. JavaScript const colors = require('colors'); colors.setTheme({ info: 'green', data: 'grey', help: 'cyan', warn: 'yellow', debug: ['blue','bold'], error: ['red', 'underline', 'bgWhite'] }); console.log("This is a debug line".debug); console.log("This is an error".error); console.log("This is a warning".warn); Output: Additional Points: We can enable and disable this module inside our code according to our needs. JavaScript const colors = require('colors'); colors.disable(); console.log('Colors module is being disabled in this zone'.red); colors.enable(); console.log('Colors module has been enabled'.rainbow); Output: You might have noticed that earlier we have used the colors module which extending the string prototype but the module also provides another way to use it.Import the module as colors/safe and then pass string using something like this,colors.someProperties("Any String") JavaScript var colors = require('colors/safe'); console.log(colors.green('Hello, GeeksforGeeks Learner')); console.log(colors.red.underline('Hello, GeeksforGeeks Learner')); console.log(colors.inverse('Hello, GeeksforGeeks Learner')); Output: Conclusion: This was the general introduction to the colors module, and you can explore it more in your own way also you can check out the official docs and repository of the module. Comment More infoAdvertise with us Next Article Explain Colors Module in Node.js mrtwinklesharma Follow Improve Article Tags : Web Technologies Node.js NodeJS-Questions Similar Reads Explain the use of crypto module in Node.js In this article, we will explore the crypto module and what are its uses in Node.js. NodeJS supports a large number of third-party modules. These modules can be used for performing different kinds of tasks. The crypto module is also a 3rd party module that can be imported and used in NodeJS. This mo 3 min read What are modules in Node JS ? In NodeJS, modules are encapsulated units of code that can be reused across different parts of an application. Modules help organize code into smaller, manageable pieces, promote code reusability, and facilitate better maintainability and scalability of NodeJS applications. Types of Modules:Core Mod 2 min read What are Modules in Node.js ? In Node.js Application, a Module can be considered as a block of code that provide a simple or complex functionality that can communicate with external application. Modules can be organized in a single file or a collection of multiple files/folders. Almost all programmers prefer modules because of t 5 min read Explain V8 engine in Node.js The V8 engine is one of the core components of Node.js, and understanding its role and how it works can significantly improve your understanding of how Node.js executes JavaScript code. In this article, we will discuss the V8 engineâs importance and its working in the context of Node.js.What is a V8 7 min read Node.js Local Module A local module in Node.js refers to a custom module created in an application. Unlike the built in or third-party modules, local modules are specific to the project and are used to organize and reuse your code across different parts of your application.Local Module in Node.jsLocal modules in Node.js 2 min read Node Export Module In NodeJS, module.exports is used to share functions, objects, or values from one file to the other file so that other files can use them. This is an essential part of organizing and reusing code across different parts of your application, making it easier to manage and maintain.Hereâs how exporting 5 min read How To Create Modules in NodeJS? Modules are the building blocks of NodeJS code. They help you break down your project into smaller, manageable pieces, each with its own job.To create a module, just make a JavaScript file and export what you want to share. Other files can then import and use those exports, adding that functionality 3 min read Deploying NPM Modules in AWS Lambda AWS Lambda definitely does change the way in which developers build and deploy their applications. it provides a serverless computing environment in which code can be executed in response to specific events without the need to manage the environment. When working with AWS Lambda, especially with Nod 6 min read How to write code using module.exports in Node.js ? module is a discrete program, contained in a single file in Node.js. They are tied to files with one module per file. module.exports is an object that the current module returns when it is "required" in another program or module. We are going to see a simple code like the calculator to learn how to 3 min read How to use EcmaScript Modules in Node.js ? Using ECMAScript Modules (ES Modules or ESM) in Node.js allows you to take advantage of modern JavaScript syntax for organizing and managing your code. ECMAScript Modules provide a more structured and standardized way to work with modules compared to CommonJS, which has been traditionally used in No 2 min read Like