Configuring 'simplest' Node.js + Socket.io + Express Server
Realized after setting up a simple node.js socket.IO server that it isn't sufficient to handle even the simplest webpages containing script tags. So I investigating express which i
Solution 1:
- Remove the first
app.configure
wrapper but leave it's contents. It is useless in general, but especially if you don't pass an argument to it. - Remove
methodOverride
andbodyParser
as you aren't using them
Solution 2:
Thanks for all the replies. Finally have something that works and am posting so someone else may benefit. My first attempt(above) was obviously NOT the simplest solution:)
//npm install express
//npm install socket.io
var express = require('express');
var server = express.createServer();
server
.use( server.router )
.use( express.static(__dirname+'/public') )
.get('/api', function(req, res) {
res.write('API');
});
server=server.listen(3000);
var io = require('socket.io');
var socket = io.listen(server);
socket.on('connection', function (client){
// new client is here!
});
Post a Comment for "Configuring 'simplest' Node.js + Socket.io + Express Server"