-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (27 loc) · 905 Bytes
/
Copy pathapp.js
File metadata and controls
35 lines (27 loc) · 905 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
//Taking express to the project
const express = require('express');
const app = express();
const dotenv = require('dotenv');
const mongoose = require('mongoose');
const cors = require('cors');
dotenv.config();
//Import Routes
const usersRoute = require("./routes/user");
const postRoute = require("./routes/post");
app.use(cors({
exposedHeaders: ['Content-Length', 'token'],
}));
// app.use(cors());
app.use(express.json());
//Adding middleware to point to userRoute
app.use('/users',usersRoute);
app.use('/post',postRoute);
//Connect to DB
mongoose.connect(process.env.DB_CONNECTION, { useNewUrlParser: true, useUnifiedTopology: true }, () => {
console.log('Connected to MongoDB');
}).catch(err => {
console.log('Could not connect to the database. Exiting now...', err);
process.exit();
});
//Telling Which port to listen to
app.listen(3000,() => console.log("Server Started"));