Home Useful NPM (v8) commands
Post
Cancel

Useful NPM (v8) commands

NPM (Node Package Manager) is an essential tool for anyone developing with JavaScript. So in this post I will list some useful commands when using NPM.

Starting a project

We can start a project by running npm init.

We can also do npm init -y if we want a default package.json.

Searching packages

You can fetch NPM packages in two ways. The first way is by directly accessing the NPM website. The second way is using the NPM CLI:

1
npm search <package>

Installing packages

A very important NPM command is install. It allows us to add dependencies to our project.

Some use cases:

1
2
3
4
5
6
npm install   # install the packages specified in package.json
npm install package   # install a package
npm install package@4.0.1   # install a specific version
npm install package@latest   # install the latest version
npm install package -D   # install as development dependency
npm install -g package   # install package globally

Uninstalling packages

We can uninstall a package using uninstall:

1
npm uninstall package

Updating packages

We can update packages using update:

1
2
npm update // update packages
npm update package // update a specific package

We can still list outdated packages by doing:

1
npm outdated

Other useful NPM commands

Some other commands that can be useful when we are working with NPM:

1
2
3
4
npm login   # log in
npm logout   # log out
npm whoami   # display logged in user
npm publish   # publish a package
This post is licensed under CC BY 4.0 by the author.
Recently Updated
Trending Tags
Contents
Trending Tags