Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon


26. January 2012

 

 

OK, so I may just be late to the party on this CtotW, as this product is currently one of the darlings of the programming world but I ignored it completely until now.  What is it I ignored so completely and now am rather enamored of?

 

Node.js

 

 

What exactly is Node?  Well basically they ripped the V8 Engine ( yeah, it’s actually called that ) that powers the Javascript engine in Google Chrome and instead used it for creatinglogo-light server side applications, like you would traditionally make using ASP.Net or JSP.  In addition to providing a server side Javascript implementation, they have implemented a number of modules ( in C++ ) to handle many common tasks, from creating an HTTP server to cryptography.  You can of course create your own add-ons in C++.  Of course, as with all things Google, the build process is a bit convoluted and poorly documented, especially for Windows based developers.

 

 

So, why exactly have I ignored Node until now?  Frankly, I hate developing in Javascript, or at least I thought I did.  Reality is, I hate developing in Javascript for browsers!  Once you move yourself out of the browser, it becomes a much more pleasant experience!

 

 

 

What exactly makes Node so enticing?  You can make light weight, simple, scalable and asynchronous servers with absolutely no other software required.  Simple run node.exe “yourAppName” and you have a running server, no need to install Java or configure a web server.  Consider the following Hello World, a completely functional web server in just a few lines of code:

 

var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(8124, "127.0.0.1");

 

Pretty simple eh?

 

 

There are a few downsides though.  Since Node.exe runs as a single process, so will your application.  This means you are tied to a single core per instance of node.  Also, tooling support is a bit lacking.  I tried out the excellent (in concept ) Cloud9 online IDE but simply put, it didn’t work.  I really hope this changes soon, as a web based IDE sounds about perfect.  I am currently trying out WebStorm, but have formed no opinion yet.  Book support is quite limited as well, with Node Web Development and Node: Up and Running: Scalable Server-Side Code with JavaScript  being the only two published books at the moment, although a number of others are in the works.  No doubt as Node matures, so will the educational and tooling support available for it.

 

 

I am going to do a quick test of using Node.js as a simple game server for an SFML based game.  I will update here accordingly when (if) that is complete.

Cool Thing of the Week

blog comments powered by Disqus

Month List

Popular Comments