-
Notifications
You must be signed in to change notification settings - Fork 32
/
server.js
31 lines (28 loc) · 980 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
////////////////////////////////////////////////////////
// IMPORTS
////////////////////////////////////////////////////////
// eslint-disable-next-line no-unused-vars
import dotenv from 'dotenv/config'; // importing .env vars
import app from './app.js';
import log from './utils/log.js';
////////////////////////////////////////////////////////
// HANDLING NODEJS ERRORS
////////////////////////////////////////////////////////
process.on('uncaughtException', err => {
log(err, 'error');
process.exit(1);
});
////////////////////////////////////////////////////////
// STARTING SERVER
////////////////////////////////////////////////////////
const port = process.env.PORT || 3000;
const server = app.listen(port, () =>
log(
`server running in ${process.env.NODE_ENV} mode at port ${port}`,
'success'
)
);
process.on('unhandledRejection', err => {
log(err, 'error');
server.close(() => process.exit(1));
});