Game Development with Javascript and Node.JS?

This post is more or less my notes from a moment of intense burning curiosity earlier in the day.  I'll tag this if I come back to it but it was a compelling enough thought to stand up a CentOS 6.4 VM in VMWare Player, built node 0.10.26 and started installing some libraries out of pure curiosity.  

Is there a reason why not to write a backend in Node.JS with WebSockets other than the obvious issues with performance, scalability, stability, availability, etc?  And has anyone done it?  Turns out the answer is kind-of sort-of.  

And why would you want to? Except why not? We're doing a thought experiment and Google makes thought experiments easy.  

After digging in some articles, I found several interesting HTML5/Javascript toolkits out there wrapping the new Chrome WebGL standard(-ish) that look promising for front end game development.  

From a quick look, my favorite so far is Game Closure.  This has the most promise but maybe because it has clever front end web design and the curious hordes are easily sucked in by clever web design.  It may have some horrible flaw I'm missing but it doesn't look it.  This looks worth downloading and taking out for a spin.  The open source license helps.

Second do that is CraftyJS and EnchantJS but they both feel a little abandonwarey, the latter far more than the former.  The toolkits have some demos to look at.

Back in time I spent some time thinking about writing RPG support tools for the iPad using several of XCode's provided data management libraries and a bit of Cocos2D for nice sprites, layout, and die rollers.  Programming in Objective-C is a terrible experience but XCode tries to make the experience less of an anal probe.  I made it through most of the Cocos2D tutorials before I had to give it up.  

In the three years since the Cocos2D community has developed C*+-Javascript and C*+-HTML5 bindings for Cocos2D-Javascript and Cocos2D-HTML5.  I found a complete hand-on tutorial for building an iPhone/iPad game with HTML5 and Javascript using Canvas elements with Cocos2D-HTML5.  Neat!  Looks worth trying!

If I was going to write mobile gaming with a node.js backend and make it all Javascript all the time, the Cocos2d route is my chosen front end route because I can still drop down into ObjC if necessary.  I see how Game Closure's Javascript/HTML5 libraries + Cocos2dX bindings equates to shipping a stable iPhone/iPad app in a few weeks.  It's a bit like programming on the JVM with a non-Java language -- one doesn't want to program in pure Java sometimes having Java available is a security blanket, and Apple provides numerous accessible libraries for ObjC development. 

That's the front end.  Interestingly I found two examples of backend -- BrowserQuest (code here) and Osmus (code here).  I found a talk here.  It's about a server framework called Pomelo - which is entirely in Chinese so your mileage may vary.  Looking at the source code available in github is educational.  All the examples do rely on Websocket management to drive connectivity between persistent web browsers and the backend.  

It's an interesting thought experiment to ponder Javascript through the entire game stack.  If I was going to write an experiment, it would probably be a baby MUD with an HTML5 terminal in the browser and a node.js backend with some spiffy NoSQL (cassandra or mongodb -- likely mongo because of mongoose) storage backing it.    My gut tells me one can host maybe ~200 players on a single small server if the WebSocket management is written efficiently and the packet communication size between client and server are kept small and light.

Lots of links in this article.  Make with the clicky!  Most of the active Javascript development out there is on the HTML5/Canvas/WebGL side.  The source code repositories are interesting.  Maybe someone will learn something neat.