It does add only when I execute: npm install <package_name> --save
In the documentation though: https://docs.npmjs.com/cli/install is written this:
By default, npm install will install all modules listed as dependencies in package.json.
Which is misleading.
npm install
without arguments installs all dependencies (and dev dependencies) listed in the package.json
file.
npm install --production
installs all the dependencies (but no dev dependency)
npm install <package>
installs a package and its dependencies.
npm install <package> --save
installs a package and its dependencies, and adds it in the package.json
file.
Edit: Since npm 5, --save
is implied.
No, it's not. I think you are misreading the sentence.
npm install
without any package name (as in your quote) will install all dependencies mentioned in the package.json.
Crete package.json file in your application folder.
Exp:- var/www/html/node/rest/package.json
{ "name": "node-api", "main": "server.js", "version": "0.0.1", "dependencies": { "express": "~4.0.0", "mongoose": "~3.6.13", "body-parser": "~1.0.1", "mysql": "^2.5.4" } }
Then run npm install command your application folder
Exp:- var/www/html/node/rest npm install
你可以再次运行npm init
来更新依赖信息。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.