Node.js and the JavaScript era

Original author: Michael E. Driscoll
  • Transfer
Three months ago, we decided to abandon the use of Django on our website and rewrite everything from scratch on server-side JavaScript under Node.js (if there is a time in a startup’s life when you can seriously change the infrastructure, this is at the very beginning of the way - when there is the greatest freedom maneuver).

What made us make this decision? One simple thought is that the LAMP stack is dead. In the two decades that have passed since his birth, fundamental changes have taken place in the protocols, content, servers and clients on which the Web is built. Three eras of web development can be distinguished:

1. 1991 - 1999: The era of HTML.

The HTML era was based on documents, in full accordance with Tim Berners-Lee’s original concept of a "virtual universe of interconnected documents." The web was filled with static, manually created files, the clumsy appearance of which in those browsers offended even the most unpretentious designer. Static documents were displayed in static clients.

2. 2000 - 2009: The era of LAMP.

The LAMP era was based on databases. The place of documents took the stack of web applications. CGI, PHP, Ruby on Rails, Django populated HTML templates with data from the database. Now the pages were dynamically formed on the server, but they still came to the browser in a static form.

3.2010 - ??: The era of JavaScript.

At the heart of the JavaScript era are streams of events. Modern web pages are no longer pages at all, but event-driven information-sharing applications. The basis for displaying content on the web - the document object model - still exists, but this is not so much a form for representing HTML markup as a data structure in memory generated by a JavaScript program.

The LAMP architecture is dead because few people now want to send tons of HTML markup in response to each user's movement. Instead, it is best to update small DOM fragments with AJAX. But when the amount of JavaScript code in our server templates exceeds 90%, it becomes clear that we are doing everything wrong.

If we recognize this, we will see that the main function of the server is now not the storage of documents (era of HTML) or rendering of templates (era of LAMP), but the delivery of data and functions for processing them. The server must give the client the application code, and then the data that the application inserts into the DOM.

In addition, the server must monitor the flow of events (client actions or messages from other servers, for example, a change in the stock price) and send updated data to clients in response to these events.

The architecture of Node.js is ideal for these features. Since JavaScript is used by both the client and server, it becomes possible to transfer some of the calculations to the browser, without any problems with interface mismatch and without having to write code twice that does the same thing in different languages ​​(for example, form validation).

Node.js is also great for working with event streams. Thanks to its asynchronous, non-blocking architecture, it is incredibly fast. It uses HTTP 1.1 and can hold thousands of open connections at once.

Finally, it is worth mentioning that events are nothing more than data packets, and JSON is gradually becoming a lingua franca for data on today's web. JSON is the most convenient for client-side JavaScript applications. And for Node.js, this is the native format.

The era of JavaScript will transform the Web from a global digital library into a global digital nervous system, the capabilities of which we are just beginning to realize.

About the author:
LinkedIn profile ,
personal site .

Also popular now: