-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
48 lines (39 loc) · 1.04 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
var express = require('express')
var cors = require('cors')
var bodyParser = require('body-parser')
const mongoose = require('mongoose')
var port = process.env.PORT || 3000
var Users = require('./routes/Users')
var Events = require('./routes/Events')
var app = express()
app.use(cors())
app.use(bodyParser.json())
app.use(
bodyParser.urlencoded({
extended: false
})
)
var Server = require('socket.io')
var http = require('http').createServer(app)
const io = Server(http);
app.use((req, res, next) => {
req.io = io;
next();
});
io.on("connect", (socket) => {
console.log("Client connected");
// socket.on("disconnect", () => console.log("Client disconnected"));
});
const mongoURL = 'mongodb://localhost:27017/sbs'
mongoose.connect( mongoURL, {
useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false
}).then(() =>
console.log('MongoDB Connected')
).catch(err =>
console.log(err)
)
app.use('/users', Users)
app.use('/api', Events)
http.listen(port, function() {
console.log('Server is running on port: ' + port)
})