Saturday, 1 October 2011

Creating a boiler plate for nodeJS

Project : https://github.com/IrishAdo/NodeJS-BoilerPlate

The first thing you realise once you start to develop your first few nodeJS applications are that there is no one "Server" solution but rather a more a bespoke solution with some common functionality across most of these.

Let me explain, we can probably split them up into several categories of applications.  Of which we’ll consider the following two set-ups.

  • Our standard web based application (both client side and server side code),
  • A server only application (server data processing) i.e. a 3d game server or a web service.

With any client/server application you have your client and your server but if your client-side application is a binary application then your architecture decision is simple but if your client-side application is a web based application.  Then you have several choices to make like will we run two servers one for page retrieval (IIS/Apache) and the other for data retrieval (nodeJS)? If we do this then we will be building an application with two distinct technologies one for the rendering of pages using (HTML, PHP, ASP, Python, Ruby etc...  If we don’t then we have to handle all types of requests for our application, i.e. data retrieval, data processing, loading html pages, serving images and other binary files.  Both of these are valid options for our web based application. For example if you currently have a web based application that requests a lot of information from the server via AJAX and are having a bottleneck on the server serving the AJAX requests then a non-blocking solution is maybe an option. So in that case you would be developing an Ajax processing server with the complete solution would be a multi-technology solution.

What should our NodeJS BoilerPlate contain?
  • Well documented code for the beginner to understand.
  • A simple structured layout that separates the server side code from the client-side code.
What still needs done on it?
  • I need to write a Text streaming function to stream html files 
  • I need to write a Binary file streamer 
  • I want to modify the server.FindHandler function to automatically find and include handlers as needed.  this just means that you don't end up with 50 if statements to include 50 handlers which will also keep that function simple.
  • Will add a resources directory beside the Application directory so that served files are held seperate, For example the default web page, a favicon.ico, all the CSS, and and client side javascript.