Node.js Modules

What is Node.js Modules ?

Node.js Modules is a set of functions which you can include in your application. Node.js Modules is same as JavaScript libraries.

Node.js provides many built-in modules like http, express fs, path, events, string, moments, events, os , url  etc.  

We can include all Node.js module in our applicaton using require() function.

How to access Node.js module?

You can access module using require() function as below.

const http = require('http');

const port = 5555;

const server = http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('Welcome to aryatechno tutorials!');

server.listen(port function() {

    console.log(`Server running at port ${port}:${port}`)



How to create our own modules?

We can create our own modules using exports keyword as below.

exports.moduleName = async function (req, res, next) {

return data;




Leave a Reply

Your email address will not be published. Required fields are marked *