-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (36 loc) · 1.06 KB
/
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
32
33
34
35
36
37
38
39
40
41
//Config
require("dotenv").config();
//Express.js
const express = require("express");
const app = express();
//Database
const connectDB = require("./config/db");
//Database connection
connectDB();
//Routes
const apiRoutes = require("./routes/apiRoutes");
//Express file upload
const fileUpload = require("express-fileupload");
//Cookie
const cookieParser = require("cookie-parser");
//socket.io
const http = require('http');
const configureSocketIO = require("./middlewares/socket")
const httpServer = http.createServer(app);
global.io = configureSocketIO(httpServer);
//error handler
const errorHandler = require("./middlewares/errorHandler")
app.use(errorHandler)
app.use(fileUpload());
app.use(cookieParser());
app.use(express.json());
app.use("/api", apiRoutes);
//Start server
/*
app.listen(process.env.PORT, () => {
console.log(`Server started successfully on port ${process.env.PORT}`)
})*/
//start server with socket.io
httpServer.listen(process.env.PORT, () =>
console.log(`Server running on port ${process.env.PORT}`)
);