-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (41 loc) · 879 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const {PORT} = require('./config');
const app = require('./app')
const {sequelize} = require('./db/sequelize');
let server;
function runServer(port) {
return new Promise((resolve, reject) => {
try {
server = app.listen(port, () => {
console.log(`App listening on port ${port}`);
resolve();
});
}
catch (err) {
console.error(`Can't start server: ${err}`);
reject(err);
}
});
}
function closeServer() {
return new Promise((resolve, reject) => {
sequelize.close();
console.log('Closing server');
server.close(err => {
if (err) {
return reject(err);
}
resolve();
});
});
}
if (require.main === module) {
runServer(PORT).catch(
err => {
console.error(`Can't start server: ${err}`);
throw err;
});
};
module.exports = {
runServer,
closeServer
};