-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
47 lines (38 loc) · 1.27 KB
/
server.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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
const likes_route = require('./routes/likes');
const post_route = require('./routes/post');
const user_route = require('./routes/user');
const comment_route = require('./routes/comment');
const type_route = require('./routes/type');
const cors = require('cors');
dotenv.config();
const host = '0.0.0.0';
const port = process.env.PORT || 5001;
app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static('uploads'));
const dbURI =
'mongodb+srv://admin:admin123@cluster0.4h1l4.mongodb.net/myFirstDatabase?retryWrites=true&w=majority';
mongoose
.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(result => {
app.listen(port, host, () => {
console.log('Server is up and running on Port:', port);
});
})
.catch(error => {
console.log(error);
});
app.get('/', async (req, res) => {
res.send('server live!');
});
app.use('/likes', likes_route.router);
app.use('/posts', post_route.router);
app.use('/users', user_route.router);
app.use('/comment', comment_route.router);
app.use('/type', type_route.router);