我想知道https://github.com/fastify/fastify-example-twitter/blob/master/package.json是如何工作的。
具体来说,它的脚本条目为:"start": "fastify index.js"
。
但是,无需在全球范围内安装fastify
。尽管如此,npm start
工作正常。它确实从fastify
开始,而从shell执行此操作会导致:-bash: fastify: command not found
调用npm start
时发生了什么?为什么我不能从命令行运行它,而npm
运行此脚本命令就好了。
答案 0 :(得分:2)
如果您的依赖项出现在npm脚本命令中,则可执行文件将添加到您的路径中。
如果您依赖于定义可执行脚本的模块,例如test 套件,然后将那些可执行文件添加到PATH中以便执行 脚本。所以,如果你的package.json有这个:
{ "name" : "foo" , "dependencies" : { "bar" : "0.1.x" } , "scripts": { "start" : "bar ./test" } }
然后你可以运行npm start来执行bar脚本,这是 导出到npm install上的node_modules / .bin目录。
答案 1 :(得分:0)
fastify
被列为依赖项,因此可以作为npm脚本运行。 mocha
,standard
和snazzy
也是如此。它们都不需要全局安装,而是通过他们的npm脚本运行。