I try to create an Azure WorkerRole with Node.js. This work's without any Problems. If I add socket.io, the Node.js Server don't start if I run in the Emulator. If I start the node.exe with my application JavaScript file, it works.
First I thought, I don't copy the socket.io modules so within the Emulator Node.js could not load the socket.io Module. But I copy all, and the error message shown is not the one, if a module is missing.
The error message on the console looks like this:
...\node_modules\socket.io\lib\Manager.js:104
Server.on<'error', function(err) {
TypeError: Object 12345 has no method 'on'
My Node.js code:
var port = process.env.port || 12345;
var io = require('socket.io').listen(port);
// start socket
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
// create new push session
socket.on('cid', function (cid) {
console.log(cid);
});
});
console.log("Server running at port %d", port);
Use var port = parseInt(process.env.port) || 12345
. According to the code, the first parameter to listen
is only treated as a port if its type is number
, but what you get from the environment is a string
.