-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
35 lines (28 loc) · 850 Bytes
/
app.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
require("dotenv").config();
const express = require("express");
const app = express();
const PORT = process.env.PORT || 5000;
// router imports
const ideaRouter = require("./routes/ideaRoutes");
// connecting to the db
const mongoose = require("mongoose");
const connectDB = async () => {
try {
await mongoose.connect(process.env.MONGO_URI);
console.log(`DB CONNECTED!`);
} catch (err) {
console.log(err);
}
};
connectDB();
// importing thrid-party middleware
const cookieParser = require("cookie-parser");
const cors = require("cors");
// setting third-party middleware
app.use(cors());
app.use(cookieParser(process.env.SIGNED_COOKIE_SECRET));
// setting express middleware
app.use(express.json());
// setting routers
app.use("/api/v1/ideas", ideaRouter);
app.listen(PORT, console.log(`Server is running at port ${PORT}`));