What are modules in Node JS ? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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 Modules: Core modules are built-in modules provided by NodeJS. They offer essential functionalities such as file system operations (fs), HTTP server (http), and utilities (util). Core modules can be accessed using the require() function without specifying a path.const fs = require('fs');Third-Party Modules: Third-party modules are created by the NodeJS community or external developers and are hosted on package registries like npm (Node Package Manager). Developers can install third-party modules using npm and include them in their applications using require().npm install package-nameconst package = require('package-name');Custom Modules: Custom modules are user-defined modules created by developers to encapsulate reusable code. Developers can create custom modules by defining functions, objects, or classes in separate files and exporting them using the module.exports or exports object.Example: Below is the code example of the custom modules: JavaScript // index.js const math = require('./math'); console.log(math.add(5, 3)); JavaScript // math.js exports.add = (a, b) => a + b; exports.subtract = (a, b) => a - b; Output:8Benefits of Using Modules:Encapsulation: Modules encapsulate code, allowing developers to hide implementation details and expose only the necessary interfaces or functionalities.Code Reusability: Modules promote code reusability by enabling developers to reuse modules across different parts of an application or in multiple applications.Maintainability: Modular code is easier to maintain and refactor, as changes made to a module's implementation do not affect other parts of the application.Scalability: Modules help organize code into smaller, manageable units, making it easier to scale applications as they grow in complexity.Conclusion:Modules are a fundamental concept in NodeJS that enable developers to organize code, promote reusability, and improve the maintainability and scalability of applications. Whether using core modules provided by NodeJS, third-party modules from npm, or custom modules created by developers, understanding how to leverage modules effectively is essential for building robust and maintainable NodeJS applications. Comment More infoAdvertise with us Next Article What are modules in Node JS ? A ashishbhardwaj18 Follow Improve Article Tags : Web Technologies Node.js MERN-QnA WebTech-FAQs Similar Reads 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 Node.js Path Module The path module in Node.js is a core module that offers utilities for managing file and directory paths. It helps handle and transform paths across different operating systems, ensuring platform independence. The module includes methods for joining, resolving, and normalizing paths, among other comm 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 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 What are the Modules in Typescript ? Modules in TypeScript allow you to organize code into reusable, manageable, and logical units by encapsulating functionalities into separate files.They help avoid global namespace pollution by providing scoped declarations.Modules can be imported and exported, enabling code reuse and better maintain 4 min read Like