I have almost completed a turn-based multiplayer game with node.js and socket.io.
I have express.js as web server and another class acting as game server, using socket.io.
My problem is that these two are running in the same application. I have a web-landing page where users can log in and see their player details and chat in the lobby. Now until here there is nothing related to game logic. So i'm asking myself why in the hell is this game server running in the same app with webserver. Also note that, in the future, there may be different servers like (europe server, americas server, asia server, etc.) but the same landing page and login mechanism stays.
So what is the perfect way to achieve this?
Should i make two seperate node.js apps, one webserver and one game server. However in that case will i be able to share session data between sockets and requests?
Another drawback is that when navigating the site, any unexpected behaviour may cause the webserver to throw exception and close the application thus shutting down the game server also.
I will be happy to achieve the best practice for this kind of situations by sharing opinions.
You may have completely separate node.js apps and a common session store, such as Redis, to check if a user authenticated with the webserver before allowing access to the game server. The common session store would also help with simultaneous game servers, not just one web + one game server.
You may also prevent closing the application by catching all errors, but that is not generally recommended.
Later edit: Here is a small list of advantages and disadvantages regarding session stores. It's not for node.js, but it applies here: http://techwhizbang.com/2009/12/memcache-session-store/