-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
51 lines (39 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
42
43
44
45
46
47
48
49
50
51
const path = require("path");
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const cookieParser = require("cookie-parser");
const cors = require("cors");
const dotenv = require("dotenv");
const { rateLimiterUsingThirdParty } = require("./middleware/rateLimiter");
//Requiring routes
const authUser = require("./routes/auth");
const level = require("./routes/levels");
dotenv.config();
const db = process.env.MONGO_URI;
mongoose
.connect(db, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
})
.then(() => console.log("Database connected"))
.catch((err) => {
console.log(err);
});
app.use(
express.urlencoded({
extended: false,
})
);
app.use(bodyParser.json());
app.use(cors());
app.use(cookieParser());
app.use(rateLimiterUsingThirdParty);
app.use("/api/user", authUser);
app.use("/api", level);
const PORT = process.env.PORT || 3001;
var server = app.listen(PORT, () => {
console.log(`Server started on ${PORT}`);
});