-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (43 loc) · 1.17 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//Required dependencies
const mongoose = require("mongoose");
const express = require("express");
const http = require("http");
//Creating an Express Application
const app = express();
//Middlewares
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const cors = require("cors");
//Importing routes
const authRoutes = require("./routes/authentication");
const userRoutes = require("./routes/user");
const postRoutes = require("./routes/post");
//.env
require("dotenv").config();
//Connecting to mongodb
mongoose.connect(
process.env.ATLAS_URI,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
},
console.log("Connection established")
);
mongoose.Promise = global.Promise; //STUDY ABOUT all this
//Using middleware in app
app.use(bodyParser.json());
app.use(cookieParser());
app.use(cors());
//Using routes
app.use("/", authRoutes);
app.use("/", userRoutes);
app.use("/", postRoutes);
//Port
const port = process.env.PORT || 5000;
//Starting server
const server = http.createServer(app);
server.listen(port, () => {
console.log(`Server is up and running at ${port}`);
});