-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (27 loc) · 815 Bytes
/
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
const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
require("dotenv").config();
//setup express
const app = express();
app.use(express.json()); //middleware to manage recieving json from request
app.use(cors()); //for sending json data as response
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server run successfully on port ${PORT}`)); //now listening to port 5000
//setup mongoose
mongoose.connect(
process.env.MONGO_URL,
{
useNewUrlParser: true,
useUnifiedTopology: true,
},
(err) => {
if (err) {
throw err;
}
console.log("MongoDB connected successfully !");
}
);
//setup routes
app.use("/users", require("./routes/userRoutes"));
app.use("/articles",require("./routes/articleRoutes"));