Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clarification of the --save option for npm install

Tags:

node.js

npm

First experiences with node.js/npm. From the npm-install docs I read:

npm install takes 3 exclusive, optional flags which save or update the package version in your main package.json:

  • --save: Package will appear in your dependencies.

  • --save-dev: Package will appear in your devDependencies.

  • --save-optional: Package will appear in your optionalDependencies.

But I can't understand how it works in practice. If, for example, I run the command:

npm install bower --save-dev

I'd expect to find a package.json file in the current directory with devDependencies set to the installed version of bower, instead I find nothing.

Am I doing/expecting something wrong?

Using node v0.10.21, npm 1.3.12 on Ubuntu 12.04 x64

like image 920
Emyl Avatar asked Jan 03 '14 11:01

Emyl


1 Answers

npm won't create package.json for you, but it will create the necessary dependencies for you as long as package.json exists and is legal JSON.

Create it like so

echo {} > package.json

Then, doing npm i --save whatever will add whatever@~x.x.x as a dependency as expected. The file needs to be there, and be JSON, that's it.

npm.png

like image 154
bevacqua Avatar answered Oct 17 '22 06:10

bevacqua