-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
41 lines (31 loc) · 1.19 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
'use strict';
var express = require('express');
var routes = require('./app/routes/index.js');
var mongoose = require('mongoose');
var passport = require('passport');
var session = require('express-session');
var bodyParser = require('body-parser');
var app = express();
var server = require('http').Server(app);
const io = require('socket.io')(server);
require('dotenv').load();
require('./app/config/passport.js')(passport);
mongoose.connect(process.env.MONGO_URI);
mongoose.Promise = global.Promise;
app.use('/controllers', express.static(process.cwd() + '/app/controllers'));
app.use('/public', express.static(process.cwd() + '/public'));
app.use('/common', express.static(process.cwd() + '/app/common'));
app.use(bodyParser.urlencoded({extended:false}));
app.set('view engine','ejs');
app.use(passport.initialize());
app.use(passport.session());
var port = process.env.PORT || 3000;
server.listen(port, function () {
console.log('Node.js listening on port ' + port + '...');
});
routes(app, passport,io);
io.on('connection',function(socket){
socket.emit('greeting',{hi:'name'});
console.log('------------------- io connected');
socket.on("disconnect", () => console.log("Client disconnected"));
});