57

Node.js and Ruby on Rails: a comparison

 6 years ago
source link: https://www.tuicool.com/articles/hit/MrQ3Ib3
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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 still reigning king Ruby on Rails .

Node.js + Express.js

Node.jsis a runtime environment that executes JavaScript code server-side. It was made to be asynchronous I/O that optimizes through put and scalability in web applications that require a lot of I/O operations. It currently has a large number of frameworks, but Express.js is one of the most popular.

Currently, many companies are changing to Node.js, given the current 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.

Node.js was built to run on the v8 engine, developed by Google, which makes it very fast in comparison with other options. Its community is growing, making it more attractable, and the fact that it's a JavaScript runtime is an important point, because a lot of developers are already familiar with it. This makes it possible to develop both frontend and backend in the same language.

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.

Ruby on Rails

On the other side we have Ruby on Rails, a server-side web application framework in Ruby according to the Model-View-Controller pattern that can provide default structures for databases, web services and webpages. It follows the principle “convention over configuration” that helps reduce the number of decisions that the developer has to make.

Despite the news that announce Rails as dead, it also has its pros and cons, just like Node.js, depending on what is intended for the final product. In the following table I'll list a few points that can show the strengths and weaknesses of each :

Node.js + Express.js vs Ruby on Rails

vMRj2eI.png!web

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 is one 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.

Building an API - Express or Rails?

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 comparing 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

Express.js

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.

The Verdict

Rails is undoubtedly best when you need to manipulate a lot of databases, where you have migrations and can easily change them. Node.js is good when you want to build micro services 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.

The popularity of Node.js is undeniable and the fact that it's executing JavaScript is its biggest advantage, since there's already a big community that can make Node.js more accountable than Ruby. But Ruby on Rails is a solid choice and, as it keeps improving, it continues to adapt quickly to change, always providing new features that answer to the user's demand.

If we analyze the interest over time on each, 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.

The point of view here only shows the singularities of each one. The real purpose will always affect the choice. The best one is always that which suits better your pretended end results.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK