forked from spiicytuna/flame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (34 loc) · 1005 Bytes
/
Copy pathserver.js
File metadata and controls
43 lines (34 loc) · 1005 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
38
39
40
41
42
43
require('dotenv').config({ quiet: true });
const http = require('http');
// Secret stuff
const { initializeSecret } = require('./utils/secret');
initializeSecret();
// Database
const { connectDB } = require('./db');
// Server
const api = require('./api');
const jobs = require('./utils/jobs');
const Socket = require('./Socket');
const Sockets = require('./Sockets');
// Utils
const initApp = require('./utils/init');
const Logger = require('./utils/Logger');
const logger = new Logger();
(async () => {
const PORT = process.env.PORT || 5005;
// Init app
await initApp();
await connectDB();
await jobs();
// Create server for Express API and WebSockets
const server = http.createServer();
server.on('request', api);
// Register weatherSocket
const weatherSocket = new Socket(server);
Sockets.registerSocket('weather', weatherSocket);
server.listen(PORT, () => {
logger.log(
`Server is running on port ${PORT} in ${process.env.NODE_ENV} mode`
);
});
})();