Top 3 Best Packages Of Node.js that you should try being a Node.js Developer
Last Updated : 12 Feb, 2021
Node.js is an open-source and server-side platform built on Google Chrome’s JavaScript Engine (V8 Engine). Node.js has its own package manager called NPM( Node Package Manager) which has very useful and incredible libraries and frameworks that makes our life easier as a developer to work with Node.js.
The 3 Best Packages of Node.js that you should try as a developer are:
- Chalk Module
- Morgan Module
- Express Module
Chalk Module: Chalk is used to style the output in your terminal. As a developer, most of our time goes into looking at the terminal to view the success and error messages being logged in the console to make the debugging of our code easier but looking at the terminals plain text most of the time a developer gets bored but if we format the color based upon the success and failure messages then it would make our life easier as a developer. Node.js introduces a package called Chalk which helps us to perform the solution to the problem mentioned above.
Module Installation: You can download the chalk module using this link or install this module using the following command:
npm install chalk
After installing the chalk module, you can require it in your file using the following code:
const chalk = require('chalk');
Filename: index.js
Javascript
const chalk = require( 'chalk' ); console.log(chalk.red( 'Geeks For Geeks' )); console.log(chalk.blue( 'Geeks' ) + 'For' + chalk.red( 'Geeks!' )); console.log(chalk.blue.bgRed.bold( 'Geeks For Geeks!' )); console.log(chalk.blue( 'Geeks' , 'For' , 'Geeks!' )); console.log(chalk.red( 'Geeks' , chalk.underline.bgBlue( 'For' ) + 'Geeks' )); |
Run the index.js file using the following command:
node index.js
Output:

Chalk Module Demo
Morgan Module: Morgan is a great logging tool that anyone works with HTTP servers in node. It generally acts as middleware and allows us to easily log requests, errors, and more to the console. It is named after Dexter Morgan who is a fictional character and the antihero protagonist of the Dexter book series.
Module Installation: You can download this module using this link or install this module using the following command:
npm install chalk
After installing the chalk module, you can require it in your file using the following code:
const morgan = require('morgan');
As we know that morgan is a middleware, so we are going to use it with an express server which will make the process easier rather than using the built-in http module in Nodejs.
const express = require('express'); const morgan = require('morgan'); const app = express(); app.listen(5000, () => { console.debug('App listening on :5000'); });
To use morgan, we have a suite of presets, which are plug-and-play in morgan. To use morgan, we write morgan(‘tiny’) according to this case, tiny is the name of the predefined format string that we’re using.
For using morgan with express we require a predefined formatted string, and we can do the following task by using this code:
const app = express(); app.use(morgan(/* This is the format string */));
The template string which morgan uses is called a format string which is given below:
':method :url :status :res[content-length] - :response-time ms'
Create custom tokens using morgan: It can be achieved using the morgan.token(name, function) function. The first argument which we pass is the name of the token and the second argument is a callback function. Morgan will run each time it logs something using the token. Morgan will pass two parameters to the function i.e req and res. We can create the token which displays the domain that the request was sent through.
morgan.token('host', function(req, res) { return req.hostname; });
Express Module: Express is a lightweight web application framework for node.js used to build the back-end of web applications relatively fast and easily. It provided robust routing, and it focuses on high performance. It has super-high test coverage. It also supports 14+ template engines(Handlebars, EJS, etc).
Module Installation: You can download the chalk module using this link or install this module using the following command:
npm install express
After installing the express module, you can require it in your file using the following code:
const express = require('express');
Filename: index.js
Javascript
var express = require( 'express' ); app = express(); app.get( '/geek' , function (req, res) { res.send( 'Heyy GeeksforGeeks' ); }); app.listen(3000, function () { console.log( 'Server Listening to port 3000' ); }); |
Run the index.js file using the following command:
node index.js
Output:
Server Listening to port 3000
Similar Reads
15 npm Commands that Every Node.js Developer Should Know
NPM stands for Node Package Manager and it is the package manager for the Node JavaScript platform. It put modules in place so that node can find them, and manages dependency conflicts intelligently. Most commonly, it is used to publish, discover, install, and develop node programs. Some Important n
2 min read
What is LTS releases of Node.js why should you care ?
Node.js is a powerful and popular open-source runtime environment for JavaScript that allows developers to build scalable, high-performance web applications. One of the key features of Node.js is its ability to receive updates and new versions regularly, which can bring new features, improvements, a
3 min read
Node.js vs Browser - Top Differences That Every Developer Should Know
Node.js and Web browsers are two different but interrelated technologies in web development. JavaScript is executed in both the environment, node.js, and browser but for different use cases. Since JavaScript is the common Programming language in both, it is a huge advantage for developers to code bo
6 min read
How to Define the Required Node.js Version in package.json?
Like the other project dependencies we can also define the node js version for a project. As we know that node is javascript runtime so it will not be contained by the normal dependencies. It ensures that the project should run and install only the compaitible node and npm version. ApproachThe defin
3 min read
How to list npm user-installed packages in Node.js?
What is Node.js? Node.js is an open source and cross-platform runtime environment for executing JavaScript code outside of a browser. Click here for more. What is npm? Here, "npm" stands for "Node Package Manager" which is the package manager for Node.js and serves as a command-line utility for inte
2 min read
The Pros and Cons of Node.JS in Web Development
Node.js is a platform that allows developers to build highly scalable applications using JavaScript. It has become the most popular language for developing real-time apps, especially in the enterprise space where it can handle thousands of simultaneous connections while maintaining low latency and h
11 min read
What is package.json in Node.js ?
In the world of Node.js development, package.json is a crucial file that serves as the heart of any Node.js project. It acts as a manifest that defines the projectâs metadata, dependencies, scripts, and more. This article will provide an in-depth look at what package.json is, why it's essential, and
4 min read
Top NextJS Projects to Become a Better Developer
In today's competitive job market, you need exceptional skills to stand out from other job seekers. Simply understanding theoretical concepts will not help you land your dream job. You need to master the technology or domain you are interested in through rigorous practice. The best way to practice a
7 min read
How to manage the packages in Node.js project ?
Node.js is an open-source, cross-platform, back-end JavaScript runtime environment built on the V8 engine and executes the JavaScript code outside the browser. When working on a project in Node.js, you may write code to achieve a specific functionality or to solve a particular problem. There are som
5 min read
Top JavaScript Playgrounds every developer should try!
Javascript has seen significant advancements in recent years, allowing developers to create, edit, and run code using an online environment called âPlaygroundâ. These playgrounds offer several features over the traditional offline code editor that runs on a development environment. Just like in a re
10 min read