What are modules in node JS

Prem Tiwari - - Node.js Tutorial


A module in node.js is a functionality which organized in single and multiple JavaScript files which can be reused in all node.js application. In this tutorial, you will learn what are modules in node JS with examples.

Node.js is a lightweight JavaSrcipt based server-side framework. The core modules of nodejs include the minimum functionalities which load automatically when the Node.js process starts.

Node.js Module Types

There are three types of Node.js modules:

  • Core Modules
  • Local Modules
  • Third Party Modules

Built-in Modules

Below is the list of built-in node.js modules, which can we use in any node.js applications.

Core ModuleDescription
httphttp module includes classes, methods and events to create Node.js http server.
urlurl module includes methods for URL resolution and parsing.
querystringquerystring module includes methods to deal with query string.
pathpath module includes methods to deal with file paths.
fsfs module includes classes, methods, and events to work with file I/O.
utilutil module includes utility functions useful for programmers.

Here is an example of node js http module:

Want to execute the above example. See how to run the node.js application.

How to Create Your Own Nodejs Module

Apart from the built-in nodejs modules, you can also create your own modules. Below is an example of a custom nodejs module which prints the system date and time like Mon Oct 15 2018 12:15:24 GMT+0530 (India Standard Time).

Copy paste below code in your index.js file and execute it using the node index.js command in your command line interface.

nodejs custom modules

Do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn more node.js tutorials.


About: Prem Tiwari

Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies.