Added ability to stop server from terminal
This commit is contained in:
parent
9e2ef9cfdc
commit
13736d0ef9
2 changed files with 16 additions and 4 deletions
|
@ -14,6 +14,6 @@
|
|||
"dependencies": {
|
||||
"express": "^4.17.1",
|
||||
"morgan": "^1.10.0",
|
||||
"xml2js": "^0.4.23"
|
||||
"promptly": "^3.2.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const express = require('express');
|
||||
const morgan = require('morgan' );
|
||||
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();
|
Loading…
Reference in a new issue