flame/server.js

41 lines
968 B
JavaScript
Raw Normal View History

require('dotenv').config();
const http = require('http');
2021-10-06 12:17:31 +00:00
// Database
const { connectDB } = require('./db');
2021-10-06 12:17:31 +00:00
const associateModels = require('./models/associateModels');
// Server
const api = require('./api');
const jobs = require('./utils/jobs');
const Socket = require('./Socket');
const Sockets = require('./Sockets');
2021-10-06 12:17:31 +00:00
// Utils
const initApp = require('./utils/init');
2021-06-22 12:49:00 +00:00
const Logger = require('./utils/Logger');
const logger = new Logger();
(async () => {
2021-10-06 12:17:31 +00:00
const PORT = process.env.PORT || 5005;
// Init app
2021-11-13 22:28:43 +00:00
await initApp();
await connectDB();
await associateModels();
// 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, () => {
2021-10-06 12:17:31 +00:00
logger.log(
`Server is running on port ${PORT} in ${process.env.NODE_ENV} mode`
);
});
})();