-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (29 loc) · 853 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
33
34
35
36
'use strict';
const express = require('express');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const mongoose = require('mongoose');
const path = require('path');
const multer = require('multer');
const config = require('./server/config');
const app = express();
mongoose.connect(config.database, (err)=>{
if(err){
console.log(err);
} else{
console.log('DB Connected..');
}
});
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname,'public')));
//routes for api
const apiRouter = require('./server/routes')(app, express);
app.use('/api', apiRouter);
app.get('*',(req,res)=>{
res.sendFile(__dirname+ '/public/index.html');
});
app.listen(config.port, ()=>{
console.log('Listening on port: ' + config.port);
});