Node.js Third Party Module
Last Updated :
05 Jul, 2025
Third-party modules are external libraries maintained and built by the developer community. Unlike core modules that are added with Node.js, these modules must be installed separately using npm. They are designed to make your complex tasks easier & modify application capabilities and make development easier.
From routing and authentication to data validation and HTTP requests, third-party modules cover nearly every aspect of modern backend development.
Installing and Using Third-Party Modules
Node.js uses npm, the world’s largest software registry, to manage third-party packages. To install A module is straightforward; you just need to give the command `npm install express`
express installation
This command installs all the popular express
web framework and adds it to the project's node_modules
directory. To use the installed module you just simply need to give the `require` command .
app.js
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello Mahima!');
});
app.listen(3000, () => console.log('Server running on port 3000'));
When you start running your server on port no 3000 you will see output Hello Mahima!
Output:
outputPopular Third-Party Modules
Here are some widely adopted third-party modules and their use cases:
Module | Purpose |
---|
express | fast , minimalist web framework for building APIs and web apps |
---|
mongoose | MongoDB ODM for schema-based data modeling |
---|
axios | Promise-based HTTP client for server and browser |
---|
lodash | Utility functions for working with arrays, objects etc |
---|
dotenv | Loads environment variables from a .env file |
---|
jsonwebtoken | Implementation of JSON Web Tokens (JWT) for authentication |
---|
Express - Web Framework
Express is a fast, minimalist web framework for Node.js that simplifies the process of building web applications and APIs. It provides robust routing, middleware support, and HTTP utility methods.
filename: express.js
app.js
const express= require('express');
const app= express();
app.get('/',(req,res)=>{
res.send('Hello from Express')
});
app.listen(8080,()=>{
console.log('app created successfully');
})
Output:
express jsUse Case : Build APIs and Web Servers Quickly.
Mongoose
Mongoose is an Object Data Modeling (ODM) library for MongoDB and Node.js. It provides a straightforward way to define schemas and interact with MongoDB using JavaScript objects.
filename:index.js
index.js
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/testDB');
const userSchema = new mongoose.Schema({
name: String,
age: Number
});
const User = mongoose.model('User', userSchema);
const newUser = new User({ name: 'Alice', age: 25 });
newUser.save().then(() => console.log('User saved!'));
Output:
output
You can check the data in the database ie. username , user id, user age etc
databaseAxios
Axios is a promise-based HTTP client for Node.js and the browser. It simplifies making HTTP requests, handling responses, and managing errors.
filename: axios.js
axios.js
const axios = require('axios');
axios.get('https://jsonplaceholder.typicode.com/posts/1')
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
Output:
axioslodash - Utiity Library
Lodash is a utility library that provides helpful functions for manipulating arrays, objects, strings, and more—making JavaScript code cleaner and more readable.
filename: lodash.js
lodash.js
const _ = require('lodash');
const numbers = [10, 5, 8, 3];
const sorted = _.sortBy(numbers);
console.log(sorted); // [3, 5, 8, 10]
Output:
outputdotenv
dotenv is a zero-dependency module that loads environment variables from a .env
file into process.env
. It helps manage configuration settings securely and separately from code.
filename: .env
.env
filename: dotenvx.js
app.js
require('dotenv').config();
console.log(process.env.PORT); // 4000
Output:
dotenv
Note: You should have .env file in the same folder have Port no . i.e PORT= 4000
Nodemon
Nodemon is a development utility that automatically restarts your Node.js Application whenever file change. It is very useful during development to avoid manually stopping and restarting the server after every change.
Installation : To install nodemon you need to run this command.
nodemon - installationSyntax : To run the command using nodemon
file run using nodemonJsonwebtoken
Jsonwebtoken (or jwt
) is a module that enables you to generate and verify JSON Web Tokens, commonly used for implementing secure authentication in APIs.
filename : jsonwebtoken.js
jsonwebtoken.js
const jwt = require('jsonwebtoken');
const token = jwt.sign({ username: 'Mahima_Bhardwaj' }, 'secretKey');
console.log('JWT:', token);
const decoded = jwt.verify(token, 'secretKey');
console.log('Decoded:', decoded);
Output:
jsonwebtokenWhy Use Third-Party Modules?
- Time Efficiency- They free developers to concentrate on the essential business logic by removing the requirement to create common functionality from the ground up.
- Community Support- The majority of well-liked module are open source and upheld by vibrant communities, guaranteeing constant enhancements and bug patches.
- Scalability and Reusability- It allows a clean, modular code structure that is simpler to grow and maintain.
- Security Updates- Patches for known vulnerabilties are frequently released by its well-maintained modules, which helps to create safer applications.
Best Practices When Using Third-Party Modules
- Evaluate Module Quality: It checks all the download stats, github activity, and issue resolution trends.
- Keeps Dependencies Up to Date: It uses tools like
npm outdated
or npm-check-updates
to manage updates. - Conduct Regular Security Audits: It runs
npm audit
regularly to identify and fix known vulnerabilities. - Limit Unneccessary Dependencies: It includes only Important modules . Using excessive dependencies can flood your project and introduce maintenance challenges.
- Review Documentation Thoroughly: It helps to understand the module's API and integration patterns before implementation.
Conclusion
- They are Important to the Node.js ecosystem.
- They allow developers to build scalable, effective and maintainable applications.
- They uses best practices to ensure secured and optimized integration of these modules.
- They allows long-term project stability and performance.
Similar Reads
Node.js require Module The primary object exported by the require() module is a function. When NodeJS invokes this require() function, it does so with a singular argument - the file path. This invocation triggers a sequence of five pivotal steps: Resolving and Loading: The process begins with the resolution and loading of
3 min read
Node.js Utility Module The util module in Node.js provides a variety of utility functions that assist with tasks such as debugging, formatting, and inheritance. It includes methods for inspecting objects, formatting strings, and extending classes. Node.js Utility ModuleThe util module offers essential utilities that are n
4 min read
Node.js Utility Module The util module in Node.js provides a variety of utility functions that assist with tasks such as debugging, formatting, and inheritance. It includes methods for inspecting objects, formatting strings, and extending classes. Node.js Utility ModuleThe util module offers essential utilities that are n
4 min read
Node.js Utility Module The util module in Node.js provides a variety of utility functions that assist with tasks such as debugging, formatting, and inheritance. It includes methods for inspecting objects, formatting strings, and extending classes. Node.js Utility ModuleThe util module offers essential utilities that are n
4 min read
Node.js Request Module The request module in Node is used to make HTTP requests. It allows developers to simply make HTTP requests like GET, POST, PUT, and DELETE in the Node app. It follows redirects by default.Syntax:const request = require('request'); request(url, (error, response, body) => { if (!error && r
2 min read
Node.js VM Module The VM (Virtual Machine) module in Node.js lets you safely run JavaScript code in a separate, isolated environment. This feature is especially handy when you need to execute code without affecting the rest of your application, making it ideal for handling untrusted code or creating distinct executio
4 min read