admin管理员组文章数量:1184762
If I have a foo.js node script, is there a way for me to automatically install all the npm dependencies?
e.g. If foo.js had this:
var program = require('commander');
var cheerio = require('cheerio');
Is there any npm command or something that I could do that would read foo.js and do 'npm install commander;npm install cheerio'?
If I have a foo.js node script, is there a way for me to automatically install all the npm dependencies?
e.g. If foo.js had this:
var program = require('commander');
var cheerio = require('cheerio');
Is there any npm command or something that I could do that would read foo.js and do 'npm install commander;npm install cheerio'?
Share Improve this question edited Mar 2, 2014 at 7:30 Matt Ball 360k102 gold badges653 silver badges719 bronze badges asked Mar 2, 2014 at 7:27 sivanosivano 7291 gold badge6 silver badges12 bronze badges 2 |3 Answers
Reset to default 15List your dependencies in a package.json file. You can then run npm install
to install all dependencies.
Here's an example of a package.json file. Notice how dependencies are defined:
{
"name": "best-practices",
"description": "A package using versioning best-practices",
"author": "Charlie Robbins <[email protected]>",
"dependencies": {
"colors": "0.x.x",
"express": "2.3.x",
"optimist": "0.2.x"
},
"devDependencies": {
"vows": "0.5.x"
},
"engine": "node >= 0.4.1"
}
Source: https://blog.nodejitsu.com/package-dependencies-done-right/
There is now a tool that auto-installs required dependencies as you code.
It's called auto-install.
npm-install-peers is a npm package that will detect peers and install them.
Note that you should install it globally
本文标签: javascriptIs there a way to automatically install nodejs dependencies from a js fileStack Overflow
版权声明:本文标题:javascript - Is there a way to automatically install node.js dependencies from a .js file? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738273551a2072379.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
automatically
, first of all list themmanually
inpackage.json
file and run thenpm install
(sometimessudo npm install
) command. – Lekhnath Commented Mar 2, 2014 at 7:54