0% found this document useful (0 votes)
2 views3 pages

Week2 Node Modules Guide

Node.js modules are reusable code blocks that help organize applications by separating functionality into distinct files. There are three types of modules: built-in modules provided by Node.js, local modules created by users, and third-party modules installed via npm. Module dependencies are essential for a program's functionality and are declared using require() or import.

Uploaded by

kadamarati26
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Week2 Node Modules Guide

Node.js modules are reusable code blocks that help organize applications by separating functionality into distinct files. There are three types of modules: built-in modules provided by Node.js, local modules created by users, and third-party modules installed via npm. Module dependencies are essential for a program's functionality and are declared using require() or import.

Uploaded by

kadamarati26
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Node Modules

Overview
[Link] modules are reusable blocks of code whose existence does not impact other code
unless explicitly imported. Modules help organize and structure a [Link] application by
breaking it into separate files with specific responsibilities.

Types of Node Modules

1. Built-in Modules
These are provided by [Link] out of the box.

Module Purpose

Fs File system operations (read, write, delete


files)

http Create HTTP server and handle


requests/responses

url Parse and format URLs

Path Handle file paths

Os Provides OS-related utility methods and


properties

crypto Encrypt and hash data

Example:

const fs = require('fs');
[Link]('[Link]', 'Hello World!');

2. Local Modules
Modules created by the user for their application.

Structure:

// file: [Link]
function sayHello(name) {
return `Hello, ${name}`;
}
[Link] = sayHello;
// file: [Link]
const greet = require('./greet');
[Link](greet('Neha'));

3. Third-party Modules
Installed via npm (Node Package Manager).

Examples: express,colour

Installation:
npm install express

Usage:
const express = require('express');
const app = express();

Module Structure
Every Node module has:

- require() – to import a module

- [Link] – to export functions, objects, or values

- Its own scope (variables/functions do not pollute global scope)

Creating and Using a Custom Module

[Link]

function add(a, b) {
return a + b;
}
[Link] = { add };

[Link]

const math = require('./math');


[Link]([Link](5, 3)); // Output: 8

Summary
- Use built-in modules for common tasks.

- Use local modules to split your code logically.

- Use npm modules to add powerful third-party features.


🌐 Module Dependencies in [Link]

🔶 What are Module Dependencies?

Module dependencies refer to the modules (internal or external) that your program
requires to function properly. These dependencies are declared using require() or
import.

⚙️Module Functionality in [Link]

🔶 What is Module Functionality?

It refers to what a module does — the code, functions, or classes it exports and how they
are used.

You might also like