NodeJS: Experiments with Middle End Part 1

Back in October last year (2010) a bunch of us fled Berlin and made for Warsaw. Not just for the Vodka you understand, but more specifically for the Front-Trends conference.

One of the talks was discussing the concept of the Middle End, by Kyle Simpson. This really made an impression on me, and I think I probably bored Kyle in the bar afterwards with my drunken enthusing. When we arrived back home, my aim was to start playing around with the idea of a Middle End as soon as possible. Unfortunately, as is life, events took over (such as discovering one is going to become a dad!) and these thoughts were consigned to the back of my mind.

Until now

The more I hack around with NodeJS the more I’ve been able to experiment with different aspects of it. Well, today I began hacking around with some Middle End concepts.

The idea of the Middle End is quite simple.

In a web application there is traditionally the Front End and the Back End. The front end handles all of the client side processing (such as rendering some whizzy JQuery plugins or whatever). The back end handles the actual hard crunching, such as retrieving and adding data from the storage engine.

However, there are certain aspects that both the front end and the back end need to handle. Some things that spring to mind are: session managment, input validation and possibly some display logic (Kyle’s post goes into some more depth here).

Currently these aspects are handled both by the front end and back end code, but as traditionally front end code is JavaScript where as back end code maybe Ruby, PHP, Python, etc that means there ends up being duplication of code. Two different languages doing the same thing.

This is in direct violation of the DRY principal. Quite simply, this is a waste.

There is a solution to this waste. Using JavaScript on the server side, effectively code can now be reused. But how can you use the same piece of code for the client side as well as the server side? In my next post I’ll be looking at how to do that.