Reputation: 10536
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
Upvotes: 8
Views: 3195
Reputation: 16023
npm install
only fetches the packages from the registry and puts them in your ./node_modules. It updates your package.json to register this new dependency if you tell it to.
Your package.json has three dependency blocks :
Here is the behavior with the different usages of the npm install command:
$ npm install async #Only installs, no change made to package.json
$ npm install async --save #Installs, adds async@version to dependencies block
$ npm install async --save-dev # Installs, adds async@version to the devDependencies block
$ npm install async --save-optional # Installs, adds async@version to the optionalDependencies block
Upvotes: 4
Reputation: 48476
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.
Upvotes: 7