How do you start http-server
in the background from an npm script so that another npm script, such as a Mocha test using jsdom, can make an HTTP request to http-server
?
The http-server
package was installed with:
npm install http-server --save-dev
The package.json
file contains:
"scripts": {
"pretest": "gulp build-httpdocs",
"test": "http-server -p 7777 httpdocs/ && mocha spec.js"
},
Running npm test
successfully starts the http-server
, but of course the command hangs after showing:
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
Is there an easy way to start the web server so it does not block the Mocha tests?
Bonus: How do you shut down http-server
after the Mocha tests have run?