Created
September 10, 2014 18:18
server.js for mean.js app with socket.io - problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* Module dependencies. | |
*/ | |
var init = require('./config/init')(), | |
config = require('./config/config'), | |
mongoose = require('mongoose'); | |
/** | |
* Main application entry file. | |
* Please note that the order of loading is important. | |
*/ | |
// Bootstrap db connection | |
var db = mongoose.connect(config.db, function(err) { | |
if (err) { | |
console.error('\x1b[31m', 'Could not connect to MongoDB!'); | |
console.log(err); | |
} | |
}); | |
// Init the express application | |
var app = require('./config/express')(db); | |
var http =require('http').Server(app); | |
var io = require('socket.io')(http); | |
// Bootstrap passport config | |
require('./config/passport')(); | |
// Start the app by listening on <port> | |
//var server = app.listen(config.port); | |
//var io = require('socket.io').listen(server); | |
// Expose app | |
exports = module.exports = app; | |
// Logging initialization | |
console.log('MEAN.JS application started on port ' + config.port); | |
io.on('connection', function(socket){ | |
console.log('user connected'); | |
socket.emit('hello',{data:'test'}); | |
socket.on('test', function (data) { | |
this.emit('test:received', {data: 'test'}); | |
}) | |
socket.on('disconnect', function(){ | |
console.log('user disconnected'); | |
}); | |
}); | |
http.listen(3000,function() {console.log('listening')}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment