如果我在本地安装http-server (没有-g标志),如何使用本地目录作为根目录来运行它?
在我的根目录中,我有一个node_modules文件夹,如果我想执行http,我需要执行$node ./node_node/$node-server/bin/ http-server。
我希望使用类似于$npm http-server的命令启动http-server.如果我使用$npm start http- server,则服务器开始时不使用./作为根。
发布于 2015-01-23 14:20:00
您可以调用位于模块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 starthttps://stackoverflow.com/questions/28111346
复制相似问题