crt_featured-01

Geeking Out: Supporting Websites with Small Servers

NOTE: CRT is excited to have Mark Lesswing, Chief Technology Officer and SVP of ITS at NAR, write a series of posts on his experiences with node.js. In the article below, expounds upon the importance of Web Sockets to the future of the web. We will indicate when we have articles that are more technical as we post them. Thank you. – Chad

I have been focusing on the future of the web lately and wanted to share some insights.  HTML5 is an important step forward for websites and there are plenty of articles on the web related to new capabilities like client-side caching, geolocation and WebSockets.  I wanted to share my experience supporting HTML5.  A good place to start would be on the server side.

node.js.  I had the same first reaction you are probably having “Javascript on the Server?”.  I had to stretch my thinking to get used to the idea, but once I overcame my first reaction, I was pleasently surprised.

Node.js can support standard sockets, http as well as WebSockets.  Recalling our physics courses, supporting web sockets reminds me of entropy; the tendency of the web is move towards disarray.  Many small services brought together through the browser versus the rendering of packaged markup from a single source like a content management system.  This thinking “ups the ante” brought to us by usability approaches such as AJAX.  AJAX allowed data transfer without user interaction; pre-filled forms and DOM manipulation based on server-side code helped shape the current web.  Now imagine that same interaction over a continuous “pipe” from a server that is not necessarily serving from within your domain.  That is how I think of WebSockets.

Getting started is as easy as downloading a package from the website and executing what comes down. This will give you the “npm” command. You use this command to install extensions. Here are a couple of useful extensions:

>npm install sqlite

>npm install csv

The first extension gives you a nifty RDBMS and the second allows you to read CSV files.  I used these two to build a database and populate it with test data I maintained in a spreadsheet.

To execute a program:

>node (name_of_your_program).js

The node.js homepage has a 6 line set of Javascript that creates an http server. That’s it. Extremely simple.

If the web does move to smaller services working in concert to create a user experience, creating small servers quickly will be important.  Additionally, when the community grasps the power of WebSockets (which requires putting AJAX thoughts aside), the simplicity of node.js will double down on its promises.

ADD YOUR COMMENT