-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
32 lines (27 loc) · 941 Bytes
/
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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
// const server = require("http").Server(app);
const mongoose = require('mongoose');
const { MONGO_URI } = require('./config');
const config = require("./config");
const router = require("./router");
// configure app to get data from a POST using bodyParser()
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
mongoose.set('useCreateIndex', true); //this to fix a deprecation
mongoose.connect(MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log('MongoDB connected!'))
.catch(err => console.log(err));
app.use('/api', router);
app.get('/', (req, res) => {
res.send('Hello this is CHATTER application!');
});
let PORT = config.PORT;
app.listen(PORT, ()=>{
console.log("server listen on port "+PORT+" with "+config.HOST);
});
module.exports = app;