Web Development Frameworks and Why Node.js Matters
Web Development Frameworks and Why Node.js Matters

What are web development frameworks?

There are many web development frameworks out there today: Rails, Django, and Laravel to name a few. At a very high level, a framework is a combination of a programming language and a set of code libraries and tools using that language that allow us to build the structure and functionality of a web application. This structure includes the front-end (client-side) languages understood by the browser, and the back-end (server-side) languages that program application logic and communication with any number of SQL or NoSQL databases. The front-end browser and the back-end server and database are collectively referred to as the “stack,” and a full-stack developer is someone capable of programming all three with a combination of various languages and tools. The front-end consists of:

HTML: a basic structural language that creates the skeleton of a page like text, headings, paragraphs, and images.

a basic structural language that creates the skeleton of a page like text, headings, paragraphs, and images. CSS: a styling language that adds the visual elements to HTML such as colors and borders. It “skins” a page, giving it a particular look and feel.

a styling language that adds the visual elements to HTML such as colors and borders. It “skins” a page, giving it a particular look and feel. JavaScript: a scripting language that adds logic to a page and makes it interactive, allowing for a static page to become dynamic by updating content based on user actions, multimedia controls, and much more.

These three languages, collectively, is all that the browser understands. Each framework will allow you to develop this front-end. The back-end is where the framework really makes its mark by turning the page into a dynamic application well beyond the capabilities of front-end JavaScript alone. Each framework has its use cases as well as pros and cons, but until the Node.js runtime environment came along, they all had one thing in common: none of them were implemented in JavaScript. They used Python, Ruby, PHP, C#, among many others.

So What?

Running JavaScript in both the browser and on the server has many benefits, not the least of which allows developers to do things that were previously impossible or extremely challenging to implement. Let’s dive into some specifics.

For decades developers have used the stateless request-response paradigm of the web. It is stateless in that when a client sends a request to a server, the server sends a response and immediately forgets about the client. The connection is, generally speaking, one-way, in that the client must always initiate it. There have been workarounds over the years, including Flash, and Java applets, which are both security nightmares and have been mostly deprecated from the web. There is also the WebSocket API which is still widely used today for stateful communications between client and server, but this is yet another protocol separate from HTTP that requires implementation.

Enter Node.js, a JavaScript runtime environment that executes JavaScript code outside of a web browser, and unifies web development around a single programming language across the stack. Tomislov Capan writes about the benefits:

Node.js shines in real-time web applications employing push technology over websockets. What is so revolutionary about that? Well, after over 20 years of stateless-web based on the stateless request-response paradigm, we finally have web applications with real-time, two-way connections, where both the client and server can initiate communication, allowing them to exchange data freely. This is in stark contrast to the typical web response paradigm, where the client always initiates communication. Additionally, it’s all based on the open web stack (HTML, CSS and JS) running over the standard port 80.

There are performance gains in connectivity because Node.js is capable of handling many simultaneous connections with high throughput, which also makes it highly scalable. The one major contraindication for Node.js is CPU-intensive, heavy computational tasks, and another solution would be more appropriate there.

There are many important advantages to using a uniform language like in the MEAN stack, which uses JavaScript, across the entire stack. There are software performance gains as well as productivity gains for developers. One language and one data interchange format (JSON — JavaScript Object Notation) based on that language throughout! The most popular Node.js framework by far is Express, known for its lightweight, flexible, scalable, and fully customizable design. Let’s outline one example of a JavaScript-everywhere paradigm stack (MEAN stack):

JavaScript at the front-end (browser) with AngularJS which extends HTML attributes for additional functionality

Express at the back-end (server)

MongoDB as the NoSQL database that stores documents in a JSON-like format

From the MongoDB blog:

By coding with Javascript throughout, we are able to realize performance gains in both the software itself and in the productivity of our developers. With MongoDB, we can store our documents in a JSON-­like format, write JSON queries on our ExpressJS and NodeJS based server, and seamlessly pass JSON documents to our AngularJS frontend. Debugging and database administration become a lot easier when the objects stored in your database are essentially identical to the objects your client Javascript sees. Even better, somebody working on the client side can easily understand the server side code and database queries; using the same syntax and objects the whole way through frees you from having to consider multiple sets of language best practices and reduces the barrier to entry for understanding your codebase.

Conclusion

Node.js may not be the right solution for every application, but it offers something very unique by unifying the stack under one language and therefore increasing developer productivity while reducing the barrier to entry, and increases performance and scalability in many use cases.

References and Additional Resources
['Roman Tetelbaum']
['Coding', 'Nodejs', 'Software Development', 'Expressjs', 'Programming']