Concepts in Focus
1. Core Modules
The Core Modules are inbuilt in Node JS.
Some of the most commonly used are:
Module | Description |
---|---|
path | Handles file paths |
fs | Handles the file system |
url | Parses the URL strings |
1.1 Path
The path module provides utilities for working with file and directory paths. It can be accessed using:
Example:
Output
Many developers prefer Common JS Modules to ES6 syntax as ES6 syntax is in the experimental phase.
2. Package
A package is a directory with one or more modules grouped.
2.1 Node Package Manager (NPM)
NPM is the package manager for the Node JS packages with more than one million packages.
It provides a command line tool that allows you to publish, discover, install, and develop node programs.
2.1.1 CLI
NPM CLI sets up the Node JS Project to organize various modules and work with third-party packages.
Command | Description |
---|---|
npm init -y | Initializes a project and creates a package.json file |
npm install <package-name> --save | Installs the third-party packages |
3. Steps to create a Node JS Project
Run the below commands in the terminal.
- Create a new directory/folder.
- Move into the created folder.
- Initialize the project.
4. Third-Party Packages
The Third-Party Packages are the external Node JS Packages.
They are developed by Node JS developers and are made available through the Node ecosystem.
4.1 date-fns
It is a third-party package for manipulating JavaScript dates in a browser & Node.js.
Installation Command:
4.1.1 addDays
It adds the specified number of days to the given date.
Example:
Output
While creating the