DEV Community

loading...
Cover image for 10 npm Commands that every developer must know

10 npm Commands that every developer must know

Gurshehzad Singh
MERN Stack Developer | Android Developer | React | Flutter | Firebase | Open Source Contributor | Technical Blogger
・1 min read

NPM stands for Node Package Manager and it is the package manager for the Node JavaScript platform. It put modules in place so that node can find them, and manages dependency conflicts intelligently. Most commonly, it is used to publish, discover, install, and develop node programs.

Some Important npm commands every developer should know are:

1) npm i
Here i stands for install. It installs all the packages
mentioned in package.json.

2) npm install -production
It installs all the packages mentioned in package.json, except
the dev dependencies.

3) npm i lodash
It installs a package with name of "lodash", you can use your
favorite package name.

4) npm install --save-dev lodash
It installs the specific package as a dev dependency, in my case
the name is "lodash".

5) npm list
It lists the versions and name of all dependencies in the current
directory.

6) npm update
It updates all the production packages in the current directory.

7) npm install -g nodemon
It installs a package globally on your machine, with -g flag. In
my case, nodemon will be installed globally.

8) npm remove lodash
It uninstalls / removes a previously installed node module in the
current directory.

9) npm -v
It displays the npm version installed on your system.

10) npm doctor
It checks our environment so that our npm installation has what
it needs to manage our JavaScript packages.

Thanks for reading!

Discussion (21)

Collapse
robinvanderknaap profile image
Robin van der Knaap

What about npm audit and npm audit fix for security fixes?

Collapse
danielp profile image
Daniel Parmenvik

I agree with you Robin that security issues and remediation should be an important part. But I would 10/10 times use a tool that continuously checks that for you. Doing it manually is prone to fail at some time.

Collapse
robinvanderknaap profile image
Robin van der Knaap

Absolutely!

Collapse
gurshehzadsingh profile image
Gurshehzad Singh Author

Yes, they can be added here. But i just wanted to keep it brief so that new developers can get a glimpse of how to start working with npm

Collapse
admmasters profile image
Matt Revell

Might be a good shout to add it (npm audit) to your ci pipeline on push to repo, assuming you are using a ci system.

Collapse
joeattardi profile image
Joe Attardi • Edited

Good list, however npm does not actually stand for "Node Package Manager".

twitter.com/npmjs/status/105690425...

Collapse
0vortex profile image
TED Vortex (Teodor Eugen Duțulescu)

this person gets it. or rather, how to read the official docs

Collapse
alco profile image
Jakub Stibůrek

What is this trickery? 😁

Collapse
jordanfinners profile image
Jordan Finneran

I'd definitely add npm outdated and npm update to this list for package maintenance!

Collapse
gurshehzadsingh profile image
Gurshehzad Singh Author

Me too.. But i wanted to keep it short till 10 so that it doesn't get overwhelming for beginners

Collapse
matthew_riley_b4b8139bce5 profile image
Matthew Riley

npm i - installs the packages in package.json but rewrites the lock file, which because of both the ecosystem and the default behaviour of npm i -s, means that different people working on the same code base can have very different packages installed, which can lead to problems. npm ci is the better way of installing packages from package.json

Collapse
drsimplegraffiti profile image
Abayomi Ogunnusi

Thanks for this.... saved

Collapse
gcanahuirev profile image
Giuseppe

What about npm list -g --depth=0 for to list packages installed globally with npm?

Collapse
theweelab profile image
Than Phan

I think it should have npm run and npm run start for listing run commands and executing command?

Collapse
rorschach profile image
R-Lek

Initially I read 10 npm Commandments.. ;)

Collapse
mikhsanh55 profile image
mikhsanh55

Thanks for this tips, ia there more nom commands for fixing broken depedencies?

Collapse
gurshehzadsingh profile image
Gurshehzad Singh Author

Yes. You can type your issue on their official npm site and you will get info about the commands which can fix your issue.

Collapse
codecustard profile image
Emmanuel Barroga

Awesome tidbit of info!

Collapse
beyarz profile image
Beyar

These are basic commands, by the title it sounded like commands outside the basics. You automatically get to know these commands by using npm.

Collapse
gurshehzadsingh profile image
Gurshehzad Singh Author

When I say must know, it is about basics.

Collapse
minhazhalim profile image
Minhaz Halim (Zim)

Thanks for the list.....