DEV Community

Cover image for You don't need --save anymore for NPM installs

You don't need --save anymore for NPM installs

Chris Bongers on August 18, 2021

If you ever installed an NPM package the following syntax looks very familiar to you: npm install --save package_name Enter fullscreen mo...
Collapse
lionelrowe profile image
lionel-rowe

This has already been the case for 4 years, and npm has already had 2 more major versions since then. Handy info for people who didn't know, but why present it as if it's a new feature?

Collapse
david_woolf profile image
David Woolf

Some people aren’t aware of features, and it was a nice rundown of different commands. The author didn’t say it was a new feature, he specifically mentioned which NPM version came with the update.

Collapse
dailydevtips1 profile image
Chris Bongers Author

I don't present it as a new feature?
That's why I mentioned it's been available since NPM 5, but a lot of people still default to typing --save in their installs scripts, so I thought it would be a good idea to make this public announcement again.

Collapse
stojakovic99 profile image
Nikola Stojaković • Edited on

Author probably didn't know about this until recently.

Collapse
dailydevtips1 profile image
Chris Bongers Author

I do know about it, but I saw a lot of tutorials still mention the --save command, so wanted to make this publicly know ❤️

Thread Thread
sami_hd profile image
Sami

Exactly! People still mention the old way to save dependencies even nowadays

Collapse
sanijalal profile image
Abd Sani

This is good info for me as there are tutorials out there in the wild that has the —save argument and I always wondered why it was needed. Now I know its no longer needed. Good to know.

Collapse
soumavabanerjee profile image
Soumava Banerjee

Even the install can be shortened to "i".

npm i
npm i -D (for dev dependencies)

Collapse
lukasdoesdev profile image
Lukas Does Dev

uninstall can me shortened to uni

Collapse
727021 profile image
Andrew Schimelpfening

It can also be shortened to just npm un

Thread Thread
toxiapo profile image
Leon

Woo this is awesome cuz i can never spell uninstall properly

Collapse
asazutaiga profile image
asazu taiga • Edited on

or npm rm, npm r may be useful

Collapse
dailydevtips1 profile image
Chris Bongers Author

Yep! ❤️

Collapse
zakiazfar profile image
Mohd Ahmad • Edited on

use yarn instead

Collapse
727021 profile image
Andrew Schimelpfening

What reasons are there for using yarn instead, other than preference? Are there pros/cons of both? Yarn uses the NPM registry for packages, doesn’t it?

Collapse
benpai profile image
Benji Grant • Edited on

Yarn has emojis, therefore it's better 💁‍♀️

On a more serious note though, it's mostly personal preference, and I really love that I can just run yarn and will install my packages, and it's output is a lot cleaner and easier to read than what npm produces.

Collapse
ptejada profile image
Pablo Tejada

I prefer yarn myself. Less verbose and more concise API in my opinion.

Collapse
zakiazfar profile image
Mohd Ahmad

it caches packages, so it is fast

Collapse
dailydevtips1 profile image
Chris Bongers Author

I think it's a personal preference, yarn did have some issues some years ago where their registry was down all the time, so decided to stick to NPM myself.

Thread Thread
zakiazfar profile image
Mohd Ahmad

yes, absolutely

Collapse
jezmck profile image
Jez McKean

At least give some reasons why!

Collapse
zakiazfar profile image
Mohd Ahmad

its fast, easy and easy to remember commands

Thread Thread
jezmck profile image
Jez McKean

How is it different (better?) to yarn and npm?

Collapse
pawandeore profile image
pawan deore

can some one please explain me difference between --save and --save-dev

Collapse
727021 profile image
Andrew Schimelpfening

Packages installed with —save-dev are only for development. In a production environment, they won’t be installed. You usually install things like linters, compilers, etc. as dev dependencies, since you don’t need them in production.

Collapse
pawandeore profile image
pawan deore

Thanks for explanation. so just for clarification i will -> npm i bootstrap@latest --save

Thread Thread
727021 profile image
Andrew Schimelpfening

Yeah. But --save is also the default, so you can leave it out.

Thread Thread
pawandeore profile image
pawan deore

Thanks. hey we are going to change our frontend stack and SEO is main factor so what do you recommend Gatsby or NExt js (the backend is going to be php based ZEND framework's API's) and you can consider our website has blogs where content writers write blogs daily (we have builtin platform for that) also video viewing subscription based platform just like udemy so this is all we got on website so what do you recommend

Thread Thread
727021 profile image
Andrew Schimelpfening

I haven’t used Gatsby, so I can’t really compare the two.

Thread Thread
killshot13 profile image
Michael R.

Pawan, you should check out StackShare, it is a great resource for these types of architecture/stack comparisons unlike SO which mostly features on use-case specific solutions. 👍

stackshare.io

Collapse
dailydevtips1 profile image
Chris Bongers Author

Thanks for this great explanation Andrew! 🙏

Collapse
wintercounter profile image
Victor Vincent

Just like npm.

Collapse
waylonwalker profile image
Waylon Walker

--save-dev always confuses me, coming from python its generally the inverse. you add packages to your requirements.txt, then pip install -r requirements.txt or pip install -r requirements_dev.txt

Collapse
yoursunny profile image
Junxiao Shi

I wish NPM can install production and development dependencies in one command, like this:

npm i -P react react-dom -D @types/react @types/react-dom
Enter fullscreen mode Exit fullscreen mode
Collapse
727021 profile image
Andrew Schimelpfening

That would be awesome. I wonder if that’s been suggested on the npm cli GitHub repo. It might be worth checking if there’s already an issue for it.

Collapse
yoursunny profile image
Junxiao Shi
Collapse
yw662 profile image
yw662

have been doing i -D and i --save. Never even tried a simple npm i. Never knew about that.

Collapse
hasnaindev profile image
Muhammad Hasnain

I have literally never used --save flag. Pretty surprised to see this post.

Collapse
dailydevtips1 profile image
Chris Bongers Author

This was needed before version 5 of NPM, so a lot of tutorials still have the save flag mentioned ❤️

Collapse
majklzumberi profile image
majkl zumberi

Nice post!
In production build time, the optional packages how they will be handled?

Collapse
dailydevtips1 profile image
Chris Bongers Author

Not a 100% sure on that actually.
Never found a good use-case for optional packages.

But then again build-time will probably only evaluate the "need" packages