When a new project starts, there's always the need to decide which approach is better for its development. There are numerous possibilities out there and there's always those which are more popular and attractive upfront. Here I'll explore two of the most used and well-known options in the development community: the fast-growing Node.js+Express.js and the solid Ruby on Rails.
Table of Contents
What is Node.js
Many companies already changed to Node.js given the stream of opinions that are announcing the fall of Rails. However, that's not the solo reason to adopt Node.js. This decision is also supported by the desire to make products more scalable - mainly when they have a lot of user interactions - and the speed that it provides.
Why Node.js for backend
Where Node.js is used
Node.js is quite popular currently amongst big-name companies, namely Uber, Netflix, Slack or even Twitter. They are all using Node.js somewhere in their stack.
Is Node.js easy to learn
Express.js is a minimal and flexible web application framework for Node.js. It's currently very popular and a great choice when the intention is to build an app with good scalability and high interaction with I/O.
What is Ruby on Rails
Ruby on Rails is a server-side web application framework in Ruby according to the Model-View-Controller pattern. It provides default structures for databases, web services and webpages and follows the principle "convention over configuration". This helps to reduce the number of decisions that the developer has to make.
Why use Ruby on Rails
The principal rule of the language is Convention over configuration. It means that the programmer does not have to spend a lot of time configuring files to get set up. It also means that changing projects should be easy because different projects will still follow this set of rules. Also, legibility of code is not as much of a problem, since even syntax will follow the conventions.
This all leads to a more productive development environment and a faster rate of development.
How fast can you learn Ruby on Rails
Ruby on Rails is very beginner-friendly and it's actually used in several places as an entry-level programming language. It does a lot of work for you, which for a beginner it's good, but when you get the nitty-gritty then you'll want more control and to understand what's happening behind Ruby's "magic".
Is Ruby on Rails still relevant
Rails is still relevant and has a lot of positive things to offer to a project. In the current development environment, you will always want a strong and flexible backend API. That's what you can get with Rails. It's easy to start developing on it, there's a huge community still behind it and it will be hard to find a larger library of ready to use reliable components, than with the ruby gem system.
Ruby on Rails is currently more mature and has been around for some time now. One point in which Rails is clearly best is in applications with a relational database. The relational database in Node.js is underdeveloped and a comparison with Rails would not make it look good at this time. Rails provides data access right away together with database schema migrations support tools, being the top pick here.
However, Node.js is growing fast and can become the next big thing. The speed and scalability that Node.js provides are two of its biggest advantages. In some tasks that require more CPU usage, it can be a problem. Something that may shadow its qualities, but it's one single problem in an aspect in which it's not, clearly, the best possible choice. Node.js would need, in such cases, much more code than Rails to be able to achieve the same end result.
But where Node.js really shines is in real-time web applications, as it allows two-way connections, where the client and the server can start the communication. It's possible due to the fact that it uses non-blocking event-driven I/O to keep it lightweight and efficient.
Ruby on Rails
Some time ago, if you wanted to build an API, Rails wouldn’t probably be your first option. However, since the API mode from Rails 5.0, the scenario changed a bit. Rails API mode is meant to build an API, as it won’t be sending a HTML representation, only JSON.
It can provide a smoother framework that removes functionalities that you will not use and provide a more lightweight performance. This means that some middleware will be turned off, such as views, helpers and assets.
With this mode, Rails became a more reasonable option, since, even when compared with other alternatives, the functionalities that it can offer are more valuable than what competitors like Sinatra can provide.
The reason most people use Rails is that it provides a set of defaults that allows developers to get up and running quickly, without having to make a lot of trivial decisions. - http://guides.rubyonrails.org/api_app.html
On the other hand, Express.js is known to be minimalistic and flexible, as it was designed to function both as middleware and as a routing framework with a set of robust features that can simplify the rapid development. Also, it's important to highlight its great documentation.
It can be fast, as speed is guaranteed with the v8 engine, and provide all the benefits that Node.js can, which is clearly its big advantage.
If we analyze the interest overtime on each, as per the graphic below, we'll see that Node.js is rising while Ruby on Rails is facing a slow decline (which is very different from being dead at the moment).
However, both are very solid options when it comes to project development and it will take some time before one emerges as a clear winner. By that time, others will find their place in the race as well.
Rails is undoubtedly best when you need to manipulate a lot of data in a database, where you have migrations and can easily change it. Node.js fits better when you want to build microservices or need a big application that will have a lot of interactions or a real-time app. It provides speed and high capability to handle a huge number of connections.
At Imaginary Cloud we use both technologies. We have developers specialized both in Node.js and Ruby on Rails which allow us to tailor our approach according to our clients' goals and needs. Need a hand in software development with these technologies? Our team is ready to help you. Drop us a line here!
Found this article interesting? You might like these ones too!