forked from shelcia/socialgram-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (27 loc) · 908 Bytes
/
Copy pathindex.js
File metadata and controls
37 lines (27 loc) · 908 Bytes
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
const express = require("express");
const app = express();
const dotenv = require("dotenv");
const mongoose = require("mongoose");
const cors = require("cors");
const PORT = process.env.PORT || 4000;
//IMPORT ROUTES
const authRoute = require("./routes/auth/auth");
const postRoute = require("./routes/posts/post");
const userRoute = require("./routes/user/user");
dotenv.config();
//CONNECTION TO DATABASE
mongoose.connect(
process.env.DB_CONNECT,
{ useUnifiedTopology: true, useNewUrlParser: true, useFindAndModify: true },
() => console.log("connected to db")
);
//MIDDLEWARE
app.use(express.json(), cors());
//ROUTE MIDDLEWARE
app.use("/api/auth", authRoute);
app.use("/api/post", postRoute);
app.use("/api/user", userRoute);
app.get("/", (req, res) => {
res.send(`<h3>Hey! Socialgram Backend is up !</h3>`);
});
app.listen(PORT, () => console.log(`server up and running at ${PORT}`));