Last Updated: September 09, 2019
·
7.671K
· ericraio

Npm install trick

When you install a package with npm it can be a real pain in the ass to update the package.json file. So you want to use the --save flag.

npm install sax --save

In this example, the save flag will automatically append sax in your dependencies inside your package.json file and it even gets the correct version number for you.

8 Responses
Add your response

Note there's also --save-dev and --save-opt to save into development and optional dependencies respectively.

over 1 year ago ·

that awesome... I really needed something like that

over 1 year ago ·

Or use the shorthand, -S

over 1 year ago ·

Or -D... etc

over 1 year ago ·

+1

over 1 year ago ·

As an npm noob, I have this nagging question. Do both rvm install 'packagename' -g and npm install 'packagename' -g work the same/similarly? I'm referring to the -g or global flag.

Then, if not global, does one have "cd" to the correct app folder, then "npm install" in much the same way one would obviously "git init" in that folder? I assume yes, just making sure.

over 1 year ago ·

Yep the -g installs globally, you can run it from where you like

over 1 year ago ·

owesome tip.

over 1 year ago ·