-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (33 loc) · 1.26 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
const mongoose = require('mongoose');
const express = require('express');
const app = express();
const bodyParser = require('body-parser')
const http = require('http');
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);
require('./socket/socket')(io);
require('dotenv').config()
global.appConfig = require('./config');
global.authUser = null;
const userApiRouter = require('./routes/user-api');
//replacing default mongoose promie with ES6 Promise as it is depreciated.
mongoose.Promise = global.Promise;
mongoose.set('useNewUrlParser', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);
mongoose.set('useUnifiedTopology', true);
mongoose.connect('mongodb://' + process.env.DB_HOST + ':' + process.env.DB_PORT + '/' + process.env.DB_NAME);
mongoose.connection.once('open', () => {
console.log('connection has been made..');
}).on('error', (error) => {
console.log(error);
});
app.use(bodyParser.json())
app.use('/api/', userApiRouter);
app.use((req, res, next) => {
return res.status(404).send({ msg: 'Requested resounce not found.' });
});
server.listen(process.env.APP_PORT, () => {
console.log('Server listening at port http://localhost:' + process.env.APP_PORT);
});