Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
Node.js vs Browser - Top Differences That Every Developer Should Know
Next article icon

Top 3 Best Packages Of Node.js that you should try being a Node.js Developer

Last Updated : 12 Feb, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

  1. Chalk Module
  2. Morgan Module
  3. 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




// Requiring the module
const chalk = require('chalk');
  
// It is used style a string
console.log(chalk.red('Geeks For Geeks'));
  
// It is used to combine styled and normal strings
console.log(chalk.blue('Geeks') + 'For' + chalk.red('Geeks!'));
  
// Compose multiple styles using the chainable API
console.log(chalk.blue.bgRed.bold('Geeks For Geeks!'));
  
// It is used pass in multiple arguments
console.log(chalk.blue('Geeks', 'For', 'Geeks!'));
  
// It is used to nest the styles
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




// Requiring the module
var express = require('express'); 
     
// Creating express app object
app = express(); 
    
// Handling /geek Request
app.get('/geek', function(req, res) { 
    res.send('Heyy GeeksforGeeks'); 
}); 
     
// Server setup
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


Next Article
Node.js vs Browser - Top Differences That Every Developer Should Know

S

SouravGhosh12
Improve
Article Tags :
  • Node.js
  • Web Technologies
  • Node.js-Misc

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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences