-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
37 lines (29 loc) · 982 Bytes
/
Copy pathapp.js
File metadata and controls
37 lines (29 loc) · 982 Bytes
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
'use strict';
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const app = express();
// What the server should use.
app.use(cors());
app.use(express.static('public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
const config = require('./config/config');
const db = require('./database/database.js');
require('./config/routes')(app);
// Start the server.
app.listen(config.getInstance.app.port, () => console.log('Server listening on port %s!', config.getInstance.app.port));
// Close the database connection on shutdown and exit gracefully!
process.on('SIGINT', async function () {
try {
await db.getInstance.close();
console.log('Server has been shut down successfully.');
process.exit(0);
} catch (error) {
console.error('Server has been shut down with an error:');
console.error(error);
process.exit(1);
}
});