-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (36 loc) · 1.06 KB
/
index.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
42
const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
const app = express();
const http = require("http");
const server = http.createServer(app);
const io = require("socket.io")(server);
const UserRoutes = require("./routes/User");
const AuthRoutes = require("./routes/Auth");
const PostRoutes = require("./routes/Post");
const ProfileRoutes = require("./routes/Profile");
const { PORT, MONGODB_URI } = require("./config");
app.use(cors());
app.use(express.json());
app.use((req, res, next) => {
io.req = req;
req.io = io;
next();
});
app.use("/api/auth", AuthRoutes);
app.use("/api/user", UserRoutes);
app.use("/api/post", PostRoutes);
app.use("/api/profile", ProfileRoutes);
require("./socket")(io);
console.log(MONGODB_URI)
mongoose
.connect(MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
})
.then(() => {
console.log("database connected");
server.listen(PORT, () => console.log(`server started on port ${PORT}`));
})
.catch((err) => console.log(err));