DEV Community

Cover image for Using Node.js for Backend Web Development in 2022
Yuriy Luchaninov
Yuriy Luchaninov

Posted on • Originally published at mobidev.biz

Using Node.js for Backend Web Development in 2022

Developing modern software applications is an essential undertaking for any growing business. Fortunately, the ongoing advancements in application development technology have presented business owners and project managers with a plethora of options to choose from. However, the breadth of possible technologies available can be overwhelming. It’s important to choose the right tech stack for your business based on the objectives and priorities you have established.

One such technology that is widely in use today is Node.js. As a modern application framework, Node.js has been adopted by many companies to build their backend tech stack. Its usage can be seen across industries as a popular option for server-side application development.

The popularity of Node.js today is increasing exponentially. Node.js is currently in use by well-known companies like Netflix, Uber, PayPal, Twitter, and more. And among programmers, Node.js was ranked as the 6th most popular technology (though, this includes also Javascript, SQL and TypeScript, as they are used in Node.js development) according to StackOverflow’s 2021 Developer Survey, with over one-third of professional developers ranking it in the top.

Top Languages 2021

But what is Node.js? How does it work, and is it still relevant in today’s technological and business landscape? More importantly, why are so many big-name companies and professional developers using it? These are the questions we will answer in this article.

What is Node.js and How it Works

In terms of application stacks, Node.js presents an interesting intersection of frontend and backend technologies. Built on JavaScript, which is traditionally a frontend, client-side web scripting language, Node.js extends the capabilities of JavaScript to run on the backend, server-side portion of a web application architecture, as well as for serverless architecture.

Node.js does this by executing within its own runtime on the server. A good analogy to draw is the comparison between Node.js and Java, which also runs applications within their own runtime. The Node.js runtime is designed to be lightweight and efficient, with non-blocking I/O and a package manager to make building applications in the Node.js ecosystem even easier.

How Node.js Works

The package manager for Node.js is called npm. Its purpose is to serve as an index of libraries built by the Node.js community of developers which are easily shared and imported by other projects. These packages provide helpful solutions to common functions and code that simplify scaffolding new projects and improving old ones.

Node.js Frameworks / Approaches

Even though Node.js itself is a powerful and versatile platform, there are frameworks/approaches that have built upon Node.js to improve it even further.

NESTJS

NestJS is an open-source, extensible, and versatile Node.js framework which incorporates TypeScript (a superset of JavaScript which is a strongly typed programming language). It is built on an abstraction of other Node.js frameworks like Express and Fastify. This abstraction makes it easy to learn and get up to speed building projects.

NestJS is built on the concepts of Modules, Providers, and Controllers. Modules are logical units of code organized together. Every application will have at least one root Module, but more can be built on top of that as the code is organized. Providers are abstractions of code that can be injected as dependencies. Controllers handle incoming requests from the client to perform application logic and return a response.

NestJS Architecture

The NestJS framework is great for the advantages of TypeScript and the benefits of other abstracted frameworks. The ease of use and extensibility are good for developing applications around a microservice architecture as well. The framework provides a strict project structure and implies a team work of several programmers, which helps set up a less buggy development process.

ELECTRON

JavaScript is primarily a language for web application development, so it makes sense that most of the frameworks built on it are also intended for the web. However, Electron combines the Chromium rendering engine and the Node.js runtime and allows the development of desktop applications using JavaScript.

Electron simplifies desktop application development by allowing programmers to write these apps in platform-agnostic web languages like HTML5 and CSS. It also makes the packaging and installation of these applications much easier.

Electron is therefore good to consider when your business use requires a desktop application without the complexity and redundancy of developing native applications for different platforms. The Electron framework’s usage of web languages speeds up the development process and reduces the time to market for new products.

DENO

Deno was released by the creator of Node.js in 2018 to address many of the problems Node.js developers and users had experienced. Specifically, these included addressing issues around security, modules, and compatibility.

Like Node.js, the Deno runtime executes code in its own application. However, Deno programs are more secure in that the runtime executes within a sandbox, isolated from the underlying file system. This adds security that prevents attackers from “breaking out” of the executable runtime and gaining access to the server the code is running on.

Deno Sandboxing by Default

Deno also eliminates the need for a centralized package manager system like Node.js’s npm. It does this by allowing modules to be imported directly by a URL and caching those modules in case the hosting URL is unavailable.

Finally, Deno supports TypeScript and strives for enhanced browser compatibility. For these reasons, there are a number of companies who are already expressing interest in adopting Deno for their own use cases, however you should keep in mind that it is not yet supported by the major cloud providers, so Docker images should be used.

Why Use Node.js

Node.js is an applicable solution for many different types of use cases. As a primarily server-side framework, Node.js lends itself to applications within the backend side of the technology stack. Below are a few of the instances when Node.js makes sense to use.

LIGHTWEIGHT, FAST APPLICATIONS WITH REAL-TIME COMMUNICATION

Understanding the size of your product is essential for choosing the right technology to build it with. The flexible and efficient nature of Node.js lends itself to building small, fast, and scalable applications. Real-time applications like instant messaging and collaboration tools are one example of this. This, coupled with the fast synchronization abilities of Node.js also make it useful for event-based applications. Examples of these include applications that use WebSockets and WebRTC.

SERVERLESS AND MICROSERVICE ARCHITECTURE

Because of its flexibility, Node.js is very good for building both serverless and microservice-based applications. These design styles are both very popular for saving resources and efficiently managing application lifecycles.

Serverless architecture is popular for its ability to save computing costs by only requiring the resources the application needs to run with no additional overhead. These applications are stateless and lightweight. This makes Node.js integration with serverless architecture a great combination. There are npm packages for serverless design, and building a serverless Node.js application works well with an overall microservice architecture in C2C and B2C use cases when the server load is volatile.

INTERNET OF THINGS

Node.js is very good at handling simultaneous connections. Since IoT is built on many devices sending small messages that must be handled quickly, Node.js makes a good backend for these kinds of applications, providing serverless architecture and real-time communication support.

AUDIO/VIDEO PROCESSING

Node.js handles asynchronous input and output much better than other technologies. So, when combined with external media tools, Node.js can be used as an option for processing and handling multimedia data. For example, a streaming setup can be easily configured using Node.js.

RAPID DEVELOPMENT

The ease of use that Node.js offers by being built on common web languages makes ramp-up times very minimal. New products can be built quickly and brought to market without delay. The amount of engineering resources required to do so is also reduced because of this.

In practice, Node.js helps to meet strict deadlines. The product, an online marketplace for hail damage repair contractors and clients, was set to be launched before the high season started. Choosing between PHP and Node.js, we decided to go with Node.js to meet both the functional requirements and deadlines. Using isomorphic architecture allowed us to reduce the development time.

INTEGRATION WITH C++ CODE

Node.js is able to seamlessly integrate with existing C++ libraries. This is because the Node.js runtime is essentially built on a C++ server that runs on the host node. That allows Node.js to quickly transmit data between C++ and application code.

Comparing Node.js to Other Backend Technologies

It may seem confusing that Node.js is distinct from other technologies, and the differences between them might not be immediately apparent. After all, each framework is designed for a purpose. Below are some of the most common comparisons between Node.js and similar technologies.

Node.js vs Java

It is common to compare Node.js to Java because each tool runs programs within its own runtime environment. However, that is where most of the similarities end. Java is a compiled, object-oriented programming language with syntax similar to C++. Java programs are typically large and costly to develop. In contrast, Node.js programs are lightweight and based on non-compiled web languages like JavaScript. It is also much more suited for I/O applications and efficient server-side handling of HTTP requests.

So, even though Java and Node.js may share similarities in their runtime applications, their use cases are actually quite different. Due to the event loop, Node.js is more efficient when operating with I/O applications, whilst Java’s thread pool is more powerful for complex computations. However, we can leverage both as microservices in one project.

Node.js vs Python

Python is a widely popular programming language due to its simple syntax and easy usability. These make building new projects in Python very easy, which has led to its popularity and explains its similarity to Node.js. However, Python is another object-oriented language like Java. And even though it is interpreted (like JavaScript), its programs can consume large amounts of computing resources.

It is however useful in big projects for areas like AI and math-heavy simulations, which are not areas that Node.js is useful for. Python’s libraries make it easier to build the application logic, however its architecture makes performance challenging and requires a highly skilled programmer involvement.

When NOT to Use Node.js

What are the cases when Node.js should not be used?

DEVELOPING FINANCIAL SOFTWARE

Unfortunately, the financial sphere is the single sphere where Node.js is definitely not recommended because of the specifics of work with the floating decimal point—it can lead to accumulation of errors in variables that deal with finances, which is unacceptable. There are tools that allow you to build logic with high-precision calculations; however, all of them have drawbacks and must be used wisely.

APPLICATION WITH COMPLEX CPU CALCULATIONS

Node.js is not the best solution when it comes to work with highly loaded threads that involve CPU. A good example is when audio and video processing is written on the back end—as opposed to the abovementioned recommended use of external processing tools, e.g. either ffmpeg / imagemagic or external libraries of C++ or Go.

Node.js Trends in 2022 and Beyond

The domination of Node.js as a popular backend technology is well established. And with current adoption by over 20 million websites, Node.js is sure to remain in use for the foreseeable future. But looking into 2022 and beyond, how will that popularity evolve?

The advent of Deno as an alternative to Node.js is one trend that looks to continue. The improvements to security and compatibility that Deno offers are much needed as more businesses expand into web technology. Along with Deno, NestJS is gaining adoption thanks to its extensibility and modularity that make it flexible for growing apps.

The need for scalability is boosted by a widespread shift to serverless and microservice application design. These small, lightweight architectural styles are much different from the large monoliths of traditional software design. Lightweight applications are cheaper and easier to build, and their reactiveness makes them ideal for real-time applications and IoT.

Wrap Up

In summary, the number of use cases for Node.js is already large and continuing to grow as advancements in other technical areas can apply to Node.js as well. There are no indications that this growth will slow any time soon. So with the proper research and the right use cases, Node.js can be an excellent choice for building many different types of products now and in the future.

There are no “good” or “bad” technologies as such. Each one is good for its particular set of tasks. Every software product owner has to identify the most important criteria of choice, according to business goals and existing constraints—and after that, the choice will be much more obvious.

Top comments (1)

Collapse
 
eronalves1996 profile image
EronAlves1996

Just a note: Javascript is an Object Orientated Language too, however, with prototype style.

Great article! Congrats!