Overview
NPM (Node Package Manager) is the default package manager for Node.js. It is a important tool for JavaScript developers, providing access to a large repository of packages and a convenient way to manage dependencies in Node.js projects.
NPM simplifies tasks such as package installation, version management, and script execution.
Installation
Install using Node Version Manager
(This allows you to install multiple versions of Node)
Install using Homebrew
(Only for MacOS & Linux)
Download the installer
Choose your preferred Node version, Operating System and click the download button
Installation
Once the installer is downloaded, just install it like you install any other software
Usage
Initializing a Project
This command creates a package.json file in your project directory, which is used to manage the project's dependencies, scripts, and other metadata.
Installing a Package
This command installs a package locally in your project. It also updates the package.json and package-lock.json files to reflect the new dependency.
Example
This installs the express package, a popular web framework for Node.js.
Installing a Package Globally
This command installs a package globally on your system, making it available from any directory.
Example
This installs nodemon, a tool that automatically restarts Node.js applications when file changes are detected, globally.
Updating a Package
This command updates a package to the latest version. If no package name is specified, it updates all project dependencies.
Example
This updates the express package to its latest version.
Uninstalling a Package
This command removes a package from your project and updates the package.json and package-lock.json files accordingly.
Example
This uninstalls the express package.