-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (39 loc) · 1.23 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
43
44
45
46
47
48
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
const authRouter = require("./routes/auth");
const deviceRouter = require("./routes/device");
const activityRouter = require("./routes/activity");
const roomRouter = require("./routes/room");
const connectDB = async () => {
try {
console.log("connect success");
await mongoose.connect(
// `mongodb+srv://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@cluster0.dlj4r.mongodb.net/myFirstDatabase?retryWrites=true&w=majority`,
`mongodb+srv://luanluan:[email protected]/myFirstDatabase?retryWrites=true&w=majority`,
{
useUnifiedTopology: true,
useNewUrlParser: true,
}
);
} catch (err) {
console.log({ error: err });
}
};
connectDB();
const app = express();
app.use(express.json());
app.use(express.urlencoded());
app.use(cors());
app.get("/", (req, res) => {
res.send("hello");
});
app.use("/api/auth", authRouter);
app.use("/api/devices", deviceRouter);
app.use("/api/activities", activityRouter);
app.use("/api/rooms", roomRouter);
const PORT = 5000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});