Just started to learn node.js for multiplayer capabilities:
Using windows 7, npm to install node.js and components I had few issues which were making me mad
var io = require('socket.io')(http); was throwing error:
D:\projects\node\chat\index.js:3 var io = require('socket.io').(http); ^ SyntaxError: Unexpected token ( at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:901:3 some time more wiered unable to handle or no such method defined, etc.
On client side in the browser following script was not working
<script> var socket = io(); $('form').submit(function(){ socket.emit('chat message', $('#m').val()); $('#m').val(''); return false; }); socket.on('chat message', function(msg){ $('#messages').append($('<li>').text(msg)); }); </script> was throwing (not error) but message for each action you perform in web:
debug - served static content /socket.io.js After doing lot of effort I come to two easy fixes shared in answer