How to synchronize global variable access in Node.Js. Is nodejs is right choice for chat room application development?

Is NodeJS capable of supporting a multi chat room application, where clients subscribe to chat room through HttpLongPolling and WebSocket ? When I think about chat room solution, I do see there is need of sync blocks while broadcasting to long polling requests and socket connections when messages are received at diff. frequencies. AFAIK there is no multi-threading and sync block concept in JS, but still to access global variables in JS we need sync blocks. My problem is not to develop a chat room solution but it is similar to it, i.e timely message broadcasting to different users subscribed for channels. Is NodeJs is a right choice for this ?

I analysed CometD, and it seems a right choice for this solution, where it comes with the solution built in the system with channel concept. But CometD has scale-ability problem, so I am trying nodejs which seems light but need to develop this solution on NodeJs. I don't have to process the message but just to pass it to browser clients.

Any suggestion ?

I've done several multiuser/multiroom applications using from static files, longpolling (comet), sockets, websockets in several languages (c, PHP, node) and up today the best experience is from NodeJS + Socket.IO.

It's soo easy... becouse Socket.IO adapts itself to available client limitations using from longpolling to websockets or flashsockets depending on him. Nevertheless, the less you rely on longpolling, the best.

You create the Socket.IO server, configure it, and 2 events for room enter and leave (beside the rest of events you want to manage). A quick skeleton of the application would be this one. You need to control users lists, users names, etc... but it can be easily done indexing the user's data by socket.id and managing that hash with connect/disconnect events. "fn" are the client callback functions.

var http      = require('http')
  , ioo       = require('socket.io')
  ;

var app = http.createServer();
var io  = ioo.listen(app);

// ... Place here Socket.IO configuration...

var port = 8080;
app.listen( port, function() { console.log( 'Server started' ); } );

io.sockets.on( 'connection', function( socket ) {
    // Management messages
    socket.on( 'connect', function( name, fn ) { connect( socket, name, fn ); });
    socket.on( 'disconnect', function() { disconnect( socket.id ); });

    socket.on( 'joinRoom', function( roomName, fn ) { joinRoom( socket, roomName, fn ); });
    socket.on( 'leaveRoom', function( roomName, fn ) { leaveRoom( socket, roomName, fn ); });
} );


...


function joinRoom( socket, roomName, fn ) {
    socket.join( roomName );
    socket.broadcast.to( roomName ).emit( 'serverMessage', 'a user enters' );
    socket.emit( 'message', 'You enter in room ' + roomName );
}

function leaveRoom( socket, roomName, fn ) {
    socket.leave( roomName );
    socket.broadcast.to( roomName ).emit( 'serverMessage', 'a user leaves' );
    socket.emit( 'message', 'You leave room ' + roomName );
}

Refer to Socket.IO site for full description of the functions Socket.IO rooms