All Case Studies Design Development Interviews Our Way Project Management

When to Use Node.js as Your Backend

Node.js is an application runtime environment that allows you to write server-side applications in Javascript. Thanks to its unique I/O model, it excels at the sort of scalable and real-time situations we are increasingly demanding of our servers.  It’s also lightweight, efficient, and the ability to use Javascript on both frontend and backend opens new possibilities. It comes as no surprise that so many big companies have leveraged it in production. In this article, I want to discuss when it is worth using Node.js and in what cases it might not be the best idea.

Real-time applications

Node.js is a good choice for an application that has a high volume of short messages that require low latency. Such systems are called real-time applications (RTAs) and can be easily developed with Node.js. Thanks to its specifications, it’s a good choice for those real-time collaborative drawing/editing-type apps, where you can watch the document being modified live by someone else.

when use node.js backend

The list of RTAs that can be effortlessly developed with Node.js is much longer. One of the most popular ones are live-chat or instant-messaging apps. Node is also the right choice if you want to create a video conference app that will work with specific hardware or VoIP. Additionally, you might want to consider Node.js for online gaming apps or e-commerce transaction software, where online data is of much importance.

Node.js is very efficient with real-time applications: it allows handling multiple client requests, enables sharing and reusing packages of library code, and data sync between client and the server happens very fast.

Really fast and scalable environment

Ruby on Rails might not be sufficient in terms of speed if you have a ton of requests. Node.js will prove useful in a situation when something faster and more scalable than rails is needed. Its ability to process many requests with low response times, as well as sharing things like validation code between the client and server make it a great fit for modern web applications that do lots of processing on the client’s side.

Therefore, it is a popular choice among "single page application" sites where all the rendering is done on client’s side, while the backend just provides a JSON API.

It also comes in handy when you want to process a high volume of IO-bound requests. It won't really be all that effective if there is a lot of CPU processing required to serve the request. Yet, if it's primarily just shuffling data around, then it will be quite efficient because a single instance can serve a lot more requests with the same hardware compared to the usual "thick" application server (like with rails).

when use node.js backend

When you shouldn't use Node.js

Even though Node.js is – in many cases – the perfect match for building applications, there are still some bad use cases when you shouldn't consider using it.

The first thing that comes to my mind are heavy-computing apps. Node.js is based on an event-driven, non-blocking I/O model and uses only a single CPU core. CPU-heavy operations will just block incoming requests, rendering the biggest advantage of Node.js useless. Therefore, if you consider building some CPU-heavy software, try a different, more suitable technology that will give you better results.

There are more things to consider before kicking off with Node.js. Many packages for Node.js applications are available in npm. The community is vibrant, the technology is maturing, and npm is the largest available repository at the moment. However, packages vary in their quality. Sometimes, you can still encounter issues with packages supported only by individual users and not maintained properly; for instance, when connecting your Node app to obscure or old database system.

Finally, using Node.js is unnecessary for simple HTML or CRUD applications in which you don't need a separate API, and all data comes directly from the server. Your application might be marginally more scalable, but don't expect more traffic coming to your app just because you used Node.js. In such cases, you should stick to proven frameworks such as Ruby.

Wrap-up

Both Rails and Node can achieve the same results. However, there are different situations where each one works best. With Rails, you can prototype and move fast, break things, and get a crud app in an hour.

Node, on the other hand, requires more resources, but it scales better, works great with real-time tasks and is faster overall. Hopefully, the tips above will help you pick the best environment.

If you want to learn more about the advantages and disadvantages of Node.js check out our article.

Node.js books
Developing in Node.js?
Order FREE code review

New Call-to-action
READ ALSO FROM NodeJS
Read also
Need a successful project?
Estimate project or contact us