One example of receiving messages for node.js. I was using nodejs-websocket module as WebSocket server. 

My server looks like this:

var ws = require("nodejs-websocket")

var server = ws.createServer(function (conn) {
    console.log("New connection")
    conn.on("close", function (code, reason) {
        console.log("Connection closed")
    })

}).listen(8081)

setInterval(function () {
	console.log("Sending 'Test'");
	try {
		server.connections.forEach(function (con) {
				console.log("Sending 'Test'");
				con.sendText("Test");
		});
	} catch (e) {
		console.log('Error!');
		console.log(e);
	}
}, 1000);

Client looks like this:

window.onload = function () {

	function MyConnectionWrapper() {
		var self = this,
			createSocket = function () { return new WebSocket('ws://127.0.0.1:8081') },
			ws = createSocket();
			
			self.onopen = function (myFunc) {
				ws.onopen = myFunc;
			}
			
			self.onmessage = function (myFunc) {
				console.log('In self: ' + myFunc);
				ws.onmessage = myFunc;
			};
	}
	
	myConn = new MyConnectionWrapper();

	myConn.onmessage(function (myFunc) {
		console.log('In myConn: ' + myFunc);
	});
}

Here notice lines:

myConn = new MyConnectionWrapper();

myConn.onmessage(function (myFunc) {
  console.log('In myConn: ' + myFunc);
});

With first line:

myConn = new MyConnectionWrapper();

we have created socket, because automatically following code is executed:

createSocket = function () { return new WebSocket('ws://127.0.0.1:8081') },

with that myConn became WebSocket, and with self we assigned onmessage method to myConn:

self.onmessage = function (myFunc) {
  console.log('In self: ' + myFunc);
  ws.onmessage = myFunc;
};

In this case myFunc will be function which we assigned like this:

myConn.onmessage(function (myFunc) {
 console.log('In myConn: ' + myFunc);
});

Example download from here.

From Node.js v0.10.31 Manual & Documentation I copied example, like:

var http = require('http');

http.createServer(function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello World\n');
}).listen(8124);

console.log('Server running at http://127.0.0.1:8124/');

If you save example like "example.js" and after starting server in command prompt with:

node example.js

in your browser go to the address:

http://localhost:8124/

and you should see "Hello World"