NPM - Node Package Manager (2024)

Node Package Manager (NPM) is a command line tool that installs, updates or uninstalls Node.js packages in your application. It is also an online repository for open-source Node.js packages. The node community around the world creates useful modules and publishes them as packages in this repository.

NPM - Node Package Manager (1) It has now become a popular package manager for other open-source JavaScript frameworks like AngularJS, jQuery, Gulp, Bower etc.

Official website: https://www.npmjs.com

NPM is included with Node.js installation. After you install Node.js, verify NPM installation by writing the following command in terminal or command prompt.

C:\> npm -v
2.11.3

If you have an older version of NPM then you can update it to the latest version using the following command.

C:\> npm install npm -g

To access NPM help, write npm help in the command prompt or terminal window.

C:\> npm help

NPM performs the operation in two modes: global and local. In the global mode, NPM performs operations which affect all the Node.js applications on the computer whereas in the local mode, NPM performs operations for the particular local directory which affects an application in that directory only.

Install Package Locally

Use the following command to install any third party module in your local Node.js project folder.

C:\>npm install <package name>

For example, the following command will install ExpressJS into MyNodeProj folder.

C:\MyNodeProj> npm install express

All the modules installed using NPM are installed under node_modules folder. The above command will create ExpressJS folder under node_modules folder in the root folder of your project and install Express.js there.

Add Dependency into package.json

Use --save at the end of the install command to add dependency entry into package.json of your application.

For example, the following command will install ExpressJS in your application and also adds dependency entry into the package.json.

C:\MyNodeProj> npm install express --save

The package.json of NodejsConsoleApp project will look something like below.

package.json

{ "name": "NodejsConsoleApp", "version": "0.0.0", "description": "NodejsConsoleApp", "main": "app.js", "author": { "name": "Dev", "email": "" }, "dependencies": { "express": "^4.13.3" }}

Install Package Globally

NPM can also install packages globally so that all the node.js application on that computer can import and use the installed packages. NPM installs global packages into /<User>/local/lib/node_modules folder.

Apply -g in the install command to install package globally. For example, the following command will install ExpressJS globally.

C:\MyNodeProj> npm install -g express

Update Package

To update the package installed locally in your Node.js project, navigate the command prompt or terminal window path to the project folder and write the following update command.

C:\MyNodeProj> npm update <package name>

The following command will update the existing ExpressJS module to the latest version.

C:\MyNodeProj> npm update express

Uninstall Packages

Use the following command to remove a local package from your project.

C:\>npm uninstall <package name>

The following command will uninstall ExpressJS from the application.

C:\MyNodeProj> npm uninstall express

Visit docs.npmjs.com for more information on Node Package Manager.

Want to check how much you know Node.js?

NPM - Node Package Manager (2024)

FAQs

Why is npm a mess? ›

npm has this problem now because JavaScript leaves a lot to be desired in terms of base convenience functionality (left-pad), and because of JavaScript's massive popularity that won't be going away anytime soon. This whole thing is hugely educational for people designing new languages with integrated package managers.

Is npm a good package manager? ›

It's been around forever and it has the most packages on its registry. If you are in search of reliability and a large choice of packages, then your answer is to go with npm. It is the default for Node. js, so there will not be extra setups to do while starting out with a new project.

Is pnpm better than npm? ›

PNPM is a drop-in replacement for npm and is much faster and more efficient than its predecessor. It is highly disk efficient and solves inherent issues in npm. In this article, we will explain how it works and why pnpm is a perfect replacement for NPM or yarn.

How to fix npm err code eacces? ›

  1. Step 1: Avoid Using sudo with chown. The error message suggests using `sudo chown` to change the ownership of the cache folder. ...
  2. Step 2: Change Ownership of the npm Cache Folder. To resolve the EACCES error, we need to change the ownership of the npm cache folder and its contents to the current user account and group.
Jul 29, 2023

Why is npm not safe? ›

js is npm. JavaScript and npm are not any less secure than the other three ecosystems, but their ubiquity has made them a target of choice for malicious actors. Whatever open source ecosystem you prefer, malicious packages can pose serious risks to the integrity and security of your applications.

Do people still use npm? ›

The latter can be downloaded as a package via npm. We know that npm is still the most widely used package manager, but at the time it had two notorious deficiencies: its speed, and its lack of predictability in the order of installation of dependencies.

Which is the best package manager for node? ›

npm, Yarn, and pnpm stand out as the frontrunners, as they are the most widely used in the Node. js ecosystem. Each package offers unique features and capabilities tailored to address the challenges of modern development environments.

What are the downsides of pnpm? ›

Downsides of using PNPM

Due to its flat tree structure, pnpm does not support the lock files produced by NPM. However, there exists a convenient command that enables the conversion of NPM/Yarn lock files into a pnpm-compatible format. It's important to note that pnpm cannot publish packages with bundledDependencies.

What is the fastest package manager? ›

Advantages and disadvantages of PNPM (Performant NPM)

PNPM is the newest and fastest package manager.

Is NPX better than npm? ›

NPM is more widely used because it comes pre-packaged and has larger support. NPX NPX is used to execute JavaScript packages downloaded from the Node Package Manager. NPX allows running packages without installation. NPX is not installed in computers if NPM has been installed prior to 5.2.

What is npm outdated? ›

Description. This command will check the registry to see if any (or, specific) installed packages are currently outdated. In the output: wanted is the maximum version of the package that satisfies the semver range specified in package.

Should I use npm or NPX? ›

In conclusion, while npm is used for managing dependencies in a project, npx is used for executing command-line tools that are part of a package without the need for a global or local installation.

Why is npm not installing? ›

Common npm install errors and their solutions. This error occurs when npm does not have the necessary permissions to install packages or modify certain files or directories. To resolve this issue, you can try running the command with administrative privileges or fix the permissions for the specific directory.

How to clear npm error? ›

Open your Terminal or Command Prompt. Execute the Cache Clearing Command: Run $ npm cache clean --force to clear the cache.

How to solve eAccess? ›

If you see an EACCES error when you try to install a package globally, you can either:
  1. Reinstall npm with a node version manager (recommended), or.
  2. Manually change npm's default directory.

Is npm install bad? ›

It is dangerous

Due to permissions required to write to the global directories, you may need to sudo install -g toolname . Combine this with the fact that npm install will run the package's arbitrary scripts, any misconfiguration or malicious code can seriously compromise your server.

What the heck is npm? ›

npm can manage packages that are local dependencies of a particular project, as well as globally-installed JavaScript tools. When used as a dependency manager for a local project, npm can install, in one command, all the dependencies of a project through the package.

Why does npm fail? ›

The “npm command not found” error occurs when the npm executable is not found in the system's PATH environment variable. The PATH variable is a list of directories that the operating system searches for executables when you run a command in the terminal.

Why is npm so heavy? ›

🤔 Well, one of the reasons is obviously that package managers like npm has several inefficiencies in downloading node modules. That could be still solved by using a better package manager like pnpm. But reason is that JS dependencies are usually larger in size than their corresponding dependencies.

Top Articles
Latest Posts
Article information

Author: Allyn Kozey

Last Updated:

Views: 6151

Rating: 4.2 / 5 (43 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Allyn Kozey

Birthday: 1993-12-21

Address: Suite 454 40343 Larson Union, Port Melia, TX 16164

Phone: +2456904400762

Job: Investor Administrator

Hobby: Sketching, Puzzles, Pet, Mountaineering, Skydiving, Dowsing, Sports

Introduction: My name is Allyn Kozey, I am a outstanding, colorful, adventurous, encouraging, zealous, tender, helpful person who loves writing and wants to share my knowledge and understanding with you.