2️⃣

2.2 Modules and Packages

 

What are modules?

Modules for Node.js are essentially libraries for JavaScript – a single or collection of JavaScript files that communicates with an external application for its function.
These are essential to programming with Node.js as modules are reusable throughout the whole Node. js application and break down complex functionalities into simpler chunks. Each module in Node. js is self-contained, meaning it has its own context and it does not interfere with other modules or the global scope.

Module Types

Node.js contains 3 types of modules:
  1. Core Modules
  1. Local Modules
  1. Third Party Modules

Core Modules

Also known as built-in modules, these modules include the most basic functionalities of Node.js. Core modules are compiled into its binary distribution and loaded automatically when Node.js is installed.
Below is a table of the most important core modules:
Core Module
Description
http
Includes classes, methods, and events to create a Node.js http server
url
To parse URL strings
querystring
To handle URL query strings
path
To handle file paths
fs
Classes, methods, and events to handle file I/O
util
To access programmer utility functions

Previous Section

Next Section

 
⚖️
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.