【发布时间】:2015-01-23 13:48:17
【问题描述】:
如果我在本地安装 http-server(不带 -g 标志)如何以本地目录作为根目录运行它?
在我的根项目目录中,我有一个 node_modules 文件夹,如果我想执行 http-server 我需要执行 $node ./node_modules/http-server/bin/http-server。
我希望使用类似 $npm http-server 的命令启动 http-server....
【问题讨论】:
如果我在本地安装 http-server(不带 -g 标志)如何以本地目录作为根目录运行它?
在我的根项目目录中,我有一个 node_modules 文件夹,如果我想执行 http-server 我需要执行 $node ./node_modules/http-server/bin/http-server。
我希望使用类似 $npm http-server 的命令启动 http-server....
【问题讨论】:
您可以像这样调用位于模块 bin 文件夹中的可执行文件:
> ./node_modules/http-server/bin/http-server
如果你想用 npm 命令来做,你可以把它放在你的 package.json 的脚本集合中:
{
"name": "tmp",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start":"./node_modules/http-server/bin/http-server",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
然后你就可以运行了
> npm start
【讨论】: