When to use Node.js

tl;dr: Those who have followed the development of Node.js over the past few years may think that the silver bullet has been discovered. But like every technology, Node.js is not equally suitable for all scenarios.

Nevertheless, it is important not to rush things: Despite all the hype, Node.js is not equally suitable for all scenarios. Like every tool, Node.js has strengths and weaknesses. This raises the question for which projects Node.js is a good choice and for which not.

Where there's shadow…

A first clear indication of which scenarios Node.js is unsuitable for is already given by the vision mentioned on the platform's website:

„Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.”

A central aspect of Node.js is the asynchronous, non-blocking input and output of data within an event loop. Those who are familiar with these concepts know that complex processes can block the entire application.

CPU-intensive applications

Therefore, Node.js is a bad choice for computationally intensive applications - as the blog entry Node.js is cancer in October 2011 (which is no longer available) demonstrated impressively but also extremely unobjectively by calculating a Fibonacci sequence. Another disadvantage is that JavaScript always calculates with floating point numbers: On the one hand, this increases the effort unnecessarily and on the other hand leads to potential rounding errors.

Forms over Data

Classic CRUD-based applications are less sensitive. There is at least nothing against the use of Node.js in these applications. For the Forms over Data paradigm Node.js is therefore not better or worse suited than ASP.NET Core, PHP or comparable technologies. The only essential advantage of Node.js is that it offers a unified language and a unified data format for the client and the server.

…there's light

But there are also scenarios in which Node.js can definitely show its strengths. The reasons for this are JavaScript as a language, and Node.js' architecture and patterns.

JSON-based REST services

A relatively obvious scenario is JSON-based REST services: Since JSON can be processed natively on the basis of JavaScript, and Node.js is also perfectly suited for developing HTTP-based web applications, writing such web services is extremely easy. This does not even require any unusual or exotic modules: Express, which is widely used and well-known, is sufficient for most cases.

Streaming

The situation is similar with the streaming of large amounts of data: Streams are an integral core concept of Node.js to deliver data quickly and lightweight. In addition, streams in Node.js can be easily orchestrated to route data through an application in multiple ways. The proximity of JavaScript to functional and reactive programming also supports this approach.

Web real-time

Although Node.js has built-in support for the HTTP and HTTPS protocols, these are not the only viable variants. There are numerous modules that complement support for alternative protocols such as SPDY or web sockets. This enables a connection from the server to the client and on this basis push-based data transmission.

Single-page applications

Combining all this, Node.js is the perfect platform for single-page applications: First, the actual application is transferred to the web browser; then it serves only as a data container, which is addressed either via a REST-based interface or via web sockets. Since single-page applications are very JavaScript-intensive, Node.js again benefit from the use of JSON and its native support in the language.

Conclusion

The scenarios in which Node.js can play out its strengths are the future of modern web applications: JSON-based REST services, streaming, web real-time and single-page applications are trends that have been becoming increasingly difficult to ignore.

So if you are involved in the development of such services and applications, you are well advised to put Node.js on your list of technologies to use.

Twitter Facebook LinkedIn

Golo Roden

Founder, CTO, and managing partner

Since we want to deliver elegant yet simple solutions of high quality for complex problems, we care about details with love: things are done when they are done, and we give them the time they need to mature.