Do You Still Need To Use npm install –save?

Avatar photo

By George

2 min read
Bookmark this post

If you are here, it probably means you are not 100% sure whether you should be using the --save flag when running npm install --save. Since this post was written in 2024, the short answer is no, you don’t need to. Let’s see why.

When using, npm install --save (shorthand npm install -S), what you are basically asking npm is to record the packages you are installing as dependencies to your project’s package.json file.

Starting with npm version 5, you no longer need to use the –save flag

Starting with npm version 5, you no longer need to use the --save flag when installing packages. By default, npm automatically saves installed packages as dependencies in your package.json file. This means that whether you include the --save flag or not, the outcome is the same: the dependencies will be recorded in the package.json file.

What about developer dependencies?

For packages that you should handle as developer dependencies – devDependencies -, you should still use --save-dev or -D.

Interesting npm install –save flags

By the way, while writing this post, I got curious about other npm flags since I have mostly been using the two mentioned earlier. As you’d expect, there are more. Here are a few that I found particularly interesting if you want to explore further:

--save-optional

The --save-optional flag saves packages as optionalDependencies. As the name suggests, these are packages that our application may not require. During the installation process, npm will not fail if, for any reason, an optional dependency fails to install.

--save-prod

The --save-prod flag is somewhat confusing at first glance, as it behaves similarly to the --save flag. It explicitly saves any installed package to the dependencies section of the package.json file. This ensures that your application’s production dependencies include the package.

--save-peer

The --save-peer made an impression! This one saves the dependencies into a peerDependencies section. Peer dependencies specify that your package is compatible with a particular version of another package without directly including it as a dependency.

If you have used another npm interesting flag and would like to share your wisdom 🧙‍♂️, please let us know in the comments section! We’re eager to learn 🧠 more about it!

DigitalOcean Referral Badge
Tags

npm

guest
0 Comments
Inline Feedbacks
View all comments

Continue reading

Quick Guides

How to Add Sass to A Create-React-App Project

Quick Guides

How to Change The Default Port in A Create-React-App Project

Subscribe to our newsletter

Dive into the Fun Side of Tech! Posts, News, and More Delivered to Your Inbox!

Intuit Mailchimp