【发布时间】:2021-12-12 11:16:48
【问题描述】:
如何从 npm 脚本在后台启动 http-server,以便另一个 npm 脚本(例如 Mocha test using jsdom)可以向http-server?
http-server 安装包是:
npm install http-server --save-dev
package.json 文件包含:
"scripts": {
"pretest": "gulp build-httpdocs",
"test": "http-server -p 7777 httpdocs/ && mocha spec.js"
},
运行npm test成功启动http-server,但显示后当然命令挂起:
Starting up http-server, serving httpdocs/
Available on:
http://127.0.0.1:7777
http://192.168.1.64:7777
Hit CTRL-C to stop the server
有没有一种简单的方法来启动 Web 服务器,这样它就不会阻止 Mocha 测试?
奖励:在 Mocha 测试运行后如何关闭 http-server?
【问题讨论】:
-
@IleshPatel 这个问题没有被接受的答案,它不适用于 npm 脚本。
-
你是在linux/mac还是windows上?
-
两者都可以,但我真的只需要 linux/mac。
标签: javascript node.js npm background-process httpserver