1

我相信您可以使用 switcher 全局安装 npm 模块-g。例如,如果我们express使用-g切换器安装,我们可以使用该命令express生成一个新应用程序。

那么它如何运行而不必做类似的事情node express ...呢?

4

1 回答 1

2

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.

NPM docs for the bin property

于 2013-07-13T03:03:27.360 回答