Added ability to stop server from terminal

This commit is contained in:
Gnarwhal 2021-02-05 08:29:03 -05:00
parent 9e2ef9cfdc
commit 13736d0ef9
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
2 changed files with 16 additions and 4 deletions

View file

@ -14,6 +14,6 @@
"dependencies": {
"express": "^4.17.1",
"morgan": "^1.10.0",
"xml2js": "^0.4.23"
"promptly": "^3.2.0"
}
}

View file

@ -1,5 +1,6 @@
const express = require('express' );
const morgan = require('morgan' );
const promptly = require('promptly');
const config = require('./config.js').load(process.argv[2]);
@ -11,4 +12,15 @@ const app = express();
app.use("/", morgan("dev"));
app.use("/", express.static("webpage"));
app.listen(config.port);
const server = app.listen(config.port);
const prompt = input => {
if (/q(?:uit)?|exit/i.test(input)) {
server.close();
} else {
promptly.prompt('')
.then(prompt);
}
};
prompt();