我相信您可以使用 switcher 全局安装 npm 模块-g
。例如,如果我们express
使用-g
切换器安装,我们可以使用该命令express
生成一个新应用程序。
那么它如何运行而不必做类似的事情node express ...
呢?
That's because of a property in the package.json
file called bin
.
When you use it in combination with the -g
switch, npm
automatically wraps the files and make them available in your system, because when you installed node, npm modules where already added to your PATH
.
Here's an example of package.json
using the bin
property:
{
"name": "mypackage",
"version": "1.0.0",
"bin": {
"mybin": "./lib/mybin.js",
"myotherbin": "./lib/myotherbin.js"
}
}
After installing this package globally, mybin
and myotherbin
will be available in your system.