Types of Modules in Node JS | SevenMentor Training (2024)

Types of Modules in Node JS is a set of functions that can be included in your program. Node JS has its own set of modules that can be included without installation. Every module has its own context so it cannot be mixed with another module. Each module can be placed in a separate js file. Unlock your full potential with comprehensive Full Stack classes in Pune. Gain expertise in front-end and back-end development, database management, and more. Enroll now!

If you are at a beginner level in Node JS do visit: Basics Of Node JS

Node js has the following 3 types of modules:-

  1. Core modules
  2. Local Modules
  3. Third-Party Modules

Types of Modules in Node JS | SevenMentor Training (1)

Core Modules:-

There are some modules in Node Js that are included with the installation of Node JS. These modules are included in the program using require function.

e.g. const abc=required(‘abc’)

The core modules which can be included in the program are as follows:-

  • http:- It creates http server in your node js program.

e.g. var http = require(‘http’);

http.createServer(function (req, resp) {

resp.write(‘Hello Everyone!’);

resp.end();

}).listen(5052);

  • assert:- It creates a set of asserted functions that can be used for testing.

e.g. var assert = require(‘assert’);

assert(15 > 72);

  • fs:- It is used to handle the file system.

e.g. var http=require(‘http’)

var fs=require(‘fs’)

http.createServer(function(req,res)

{

fs.readFile(‘intro.html’,function(err,data)

{

res.writeHead(200,{‘Content-Type’:”text/html”})

res.write(data)

return res.end()

})

}).listen(3011)

  • path:- This module have the methods to deal with file paths.

e.g. const express=require(‘express’)

const path=require(‘path’)

const app=express()

const pageaddr=path.join(__dirname,’public’)

// app.use(express.static(pageaddr))

app.use(”,(_,resp)=>{

resp.sendFile(`${pageaddr}/index.html`)

})

app.use(‘/about’,(_,resp)=>{

resp.sendFile(`${pageaddr}/about.html`)

})

app.use(‘/contact’,(_,resp)=>{

resp.sendFile(`${pageaddr}/contact.html`)

})

app.use(‘*’,(_,resp)=>{

resp.sendFile(`${pageaddr}/notfound.html`)

})

app.listen(5004)

  • process:- It provides the information of the process which is currently running in Node Js.

e.g. process.on(‘exit’, code => {

setTimeout(() => {

console.log(‘Will not get displayed’);

}, 0);

console.log(‘Exited with status code:’, code);

});

console.log(‘Execution Completed’);

Note: Learn to build dynamic, interactive user interfaces and master the popular React library. Enroll React JS Training in Pune Now

  • os:- It provides the information about the operating system.

e.g. var os = require(‘os’);

console.log(“Platform: ” + os.platform());

console.log(“Architecture: ” + os.arch());

  • querystring:- This module is used to parse and format URL query strings.

e.g. var querystring = require(‘querystring’);

var q = querystring.parse(‘year=2015&month=march’);

console.log(q.year);

  • url:- It is used to provide utilities to parse and handle url resolution.

e.g. var url = require(‘url’);

var adr = ‘http://localhost:8080/default.htm?year=2008&month=february’;

var q = url.parse(adr, true);

console.log(q.host);

console.log(q.pathname);

console.log(q.search);

var qdata = q.query;

console.log(qdata.month);

Local Modules:-

Local modules are created in your node application at the time of creating the application.

e.g. exports.sum = function (num1, num2) {

return num1 + num2;

};

exports.subtr = function (num1, num2) {

return num1 – num2;

};

exports.multpl= function (num1, num2) {

return num1 * num2;

};

exports.divsn = function (num1, num2) {

return num1/ num2;

};

These exported functions can be used in another file using require() function like-

const calci = require(‘./calci’);

let num1=35, num2 = 30;

console.log(“Addition of 35 and 30 is “

+ calci.sum(num1, num2));

console.log(“Subtraction of 35 and 30 is “

+ calci.subtr(num1, num2));

console.log(“Multiplication of 35 and 30 is “

+ calci.multpl(num1, num2));

console.log(“Division of 35 and 30 is “

+ calci.divsn(num1, num));

Third-Party Modules:-

The modules which can be included in the program using NPM(Node Package Manager) online are called as third-party modules. We can include these modules globally or in the project folder. Third-party modules are:-

  • Express
  • Moongose
  • React
  • Angular

These modules are included using the command –

npm install express

npm install mongoose etc.

Do watch our latest video: Click Here

Author:-

Sarika Ganesh Kore

Call the Trainer and Book your free demo Class For JavaScript Call now!!!
| SevenMentor Pvt Ltd.

© Copyright 2021 | SevenMentor Pvt Ltd.

Types of Modules in Node JS | SevenMentor Training (2024)

FAQs

What are the different types of modules in NodeJS? ›

Types of Modules in Node JS
  • Core modules.
  • Local Modules.
  • Third-Party Modules.
Jun 27, 2023

What are the three types of modules? ›

The three kind of modules are Form Modules, Standard Modules and Class Modules.

Which modules are used for testing in node JS? ›

evanshortiss/nodejs-testing-examples
NameName
express-application-testingexpress-application-testing
module-testing-with-mochamodule-testing-with-mocha
proxyquire-dependency-mocksproxyquire-dependency-mocks
.editorconfig.editorconfig
7 more rows

What exactly is node modules? ›

As building blocks of code structure, Node. js modules allow developers to better structure, reuse, and distribute code. A module is a self-contained file or directory of related code, which can be included in your application wherever needed. Modules and the module system are fundamental parts of how Node.

How many modules are there in node? ›

Node.js has two module systems: CommonJS modules and ECMAScript modules. By default, Node.js will treat the following as CommonJS modules: Files with a .cjs extension; Files with a .js extension when the nearest parent package.json file contains a top-level field "type" with a value of "commonjs" .

How to list all node modules? ›

The short answer
  1. To list globally installed packages with npm, you can use the npm ls command combined with the -g flag (short for global):
  2. Alternatively, to list locally installed packages present in the node_modules folder of a project, you can navigate to your project and run the npm ls command (without the -g flag):
Feb 1, 2024

What are modules in training? ›

A training module is a focused unit within a program, providing structured instruction on specific learning objectives. It includes content, activities, assessments, and resources to help learners acquire targeted knowledge or skills. ← Previous TermTraining Metrics. Next Term →Training Needs Analysis.

What is basic modules? ›

Basic modules are those that send altered or entirely new requests to the crawler and register callbacks to handle the responses.

What are Node.js native modules? ›

Native modules refers to the modules that are written outside of JavaScript, modules that are written in C++ (C++ addons) for example and embedded into JavaScript using things like N-API (Node-API).

What is inside node modules? ›

The node_modules folder is a directory in NodeJS projects that stores third-party libraries and dependencies. It's essential for managing dependencies, which are packages or modules that a NodeJS project relies on.

What does npm stand for? ›

npm stands for Node Package Manager. It's a library and registry for JavaScript software packages. npm also has command-line tools to help you install the different packages and manage their dependencies. npm is free and relied on by over 11 million developers worldwide. You could say it's kind of a big deal.

How to include node modules? ›

How To Use Node Modules with npm and package. json
  1. Initialize a Node.js project.
  2. Install Node.js modules.
  3. Save dependencies to package.json.
  4. Use installed modules in your code.
  5. Include package.json in your project.
  6. Install dependencies from package.json.
Mar 12, 2024

What are the type of modules in node? ›

We will discuss the different types of Node.js Modules:
  • Core Modules.
  • Local Modules.
  • Third-party modules.
May 31, 2024

What are modules in js? ›

A module in JavaScript is just a file containing related code. In JavaScript, we use the import and export keywords to share and receive functionalities respectively across different modules. The export keyword is used to make a variable, function, class or object accessible to other modules.

How to run a node module? ›

The usual way to run a Node.js program is to run the globally available node command (once you install Node.js) and pass the name of the file you want to execute. While running the command, make sure you are in the same directory which contains the app.js file.

What are the different types of network modules? ›

What are the types of network modules?
  • Network modules are classified into LAN modules and WAN modules based on the network coverage.
  • LAN modules: The network coverage is within a few kilometers. ...
  • WAN modules: The network coverage ranges from tens of to hundreds of kilometers.
Oct 8, 2022

How many NPM modules are there? ›

Over 3.1 million packages are available in the main npm registry.

What are the types of function module? ›

Vijay Kumar
  • Normal Function Module.
  • RFC Function Module.
  • Update Function Module.
Jan 25, 2024

What are CommonJS modules? ›

CommonJS is a highly functional and effective module system that is used for server-side development in Node. js. It was specifically designed to solve the complex problem of organizing code in large and intricate projects.

Top Articles
COMMENTARY: Parents have a powerful role in improving literacy education
Venmo Credit Card Referrals FAQ + Terms 
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Rev. Leonie Wyman

Last Updated:

Views: 6159

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Rev. Leonie Wyman

Birthday: 1993-07-01

Address: Suite 763 6272 Lang Bypass, New Xochitlport, VT 72704-3308

Phone: +22014484519944

Job: Banking Officer

Hobby: Sailing, Gaming, Basketball, Calligraphy, Mycology, Astronomy, Juggling

Introduction: My name is Rev. Leonie Wyman, I am a colorful, tasty, splendid, fair, witty, gorgeous, splendid person who loves writing and wants to share my knowledge and understanding with you.