-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
56 lines (46 loc) · 1.42 KB
/
Copy pathserver.js
File metadata and controls
56 lines (46 loc) · 1.42 KB
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
48
49
50
51
52
53
54
55
56
/* eslint-disable no-console */
'use strict';
/** *********************************
**** node module defined here *****
********************************** */
require('dotenv').config();
const EXPRESS = require('express');
const http = require('http');
const process = require('process');
const { SERVER } = require('./config');
/** creating express server app for server. */
const app = EXPRESS();
/** ******************************
***** Server Configuration *****
******************************* */
const server = http.Server(app);
global.io = require('socket.io')(server, {
cors: {
origin: '*',
methods: ['GET', 'POST'],
},
});
/** Server is running here */
const startNodeserver = async () => {
// initialize mongo
await require('./app/startup/db_mongo')();
// initialize redis
await require('./app/startup/db_redis')();
// initialize daemons(cronjobs)
// await require('./app/startup/daemon').start();
await require('./app/startup/socket').connect(global.io);
await require('./app/startup/expressStartup')(app); // express startup.
return new Promise((resolve, reject) => {
server.listen(SERVER.PORT, (err) => {
if (err) reject(err);
resolve();
});
});
};
startNodeserver().then(() => {
console.log(`Worker thread ${process.pid} is running`);
console.log('Node server running on', SERVER.URL);
}).catch((err) => {
console.log('Error in starting server', err);
process.exit(1);
});