Node JS vs Ruby on Rails. Which is the best for web development

Author:

Dasha, marketing director

Published: September 26, 2017

Time to read: 5 min

Hi, guys, in this article we’re going to compare Node.js versus Ruby on Rails for web development. The main reason I write this article is that our team constantly being asked which language or which framework is best to learn. Anyway, we never give a simple answer because they aren’t the clear-cut answer. So I think the next best thing is to look at all facts and statistics. We’re going to take a look at some of the advantages and some of the disadvantages of both Nod.js and Ruby on Rails for server-side technologies. Before we begin I make a couple of points. So we can already hear the critics saying how are you going to compare Node.js that is a runtime to Ruby on Rails that is a framework. I get the argument what I compare are the two server-side technologies and web stacks. Now let’s get clear what’s better to learn right now and what’s better to implement for a business. I’m not saying to compare straight up features of Ruby on Rails to Nod.js. If it makes you feel better to replace Node.js with something like Express or some other node based frameworks. Anyway, we compare back-end structures and stacks, not the individual technology. Our team worked with both technologies and some of us like both technologies. I’m not promoting over the other. It’s also important to understand what works for us may not work for you and vice versa. Also, you should remember that everyone’s brain is different. There is no cookie cutter answer for this question.

Let’s go ahead and get started with looking at some of the similarities between both technologies.

  • Popular Server-Side Technologies
  • Fairly easy to learn
  • High performance
  • Used by top websites/applications
  • Strong community
  • Similar MVC based structure
  • Rapid Development

Both Node.js and Rails are well respected and popular server-side technologies that can do many different things. They can work with many different stacks and databases and so on. Both are fairly easy to learn. Node uses JavaScript and Rails uses Ruby. But Ruby and JavaScript are easier to learn than something like Java, C# or some of those higher-level languages. They’re both pretty forgiving languages and there’s a ton of resources for learning them. Node.js and Ruby on Rails perform really well and well talk about the level of performance. There are many examples of popular websites that use both technologies. Node and Rails have very strong and opinionated communities.

Rails have been around a little longer and have more old timers. But Node is becoming more popular every day. Now MVC or Model-View-Controller is a designed pattern. And Ruby on Rails is hard MVC. You have a folder for your models, your controllers, and your views. MVC is possible with certain frameworks in Node such as Express. However Express is much more flexible in its structure than Rails is. You can just take certain aspects of MVC. It’s not the only structure possible. Node and Rails are used for rapid development and prototyping. Rails has an awesome folding feature and Express as generators and command-line tools as well.

Rails Advantages

  • Consistent structure
  • Very opinionated
  • Database migrations
  • Speed of Development
  • Ruby is a great language
  • Ruby gems
  • Maturity and respected community

First, we are going to take a look at the advantages of Ruby on Rails and then the disadvantages. Going ahead we’ll take a look at Node.js. As I said Rails has a very strong MVC structure. Most Rails applications are going to look very similar in terms of the core files and folders. You have that strong foundation and then you build upon that with gems and custom packages and libraries. In addition, Rails is very opinionated meaning that it makes you adhere to its way of doing things. Rails assumes that you’re going to write code in a certain way and some people may say that’s a little restrictive. But it also makes for easier, much cleaner code and it also makes it harder to have errors and issues. It’s not restructuring in the sense that you can’t create what you want but only the way that you’re going to get there. If you do it the right way it’ll most likely be the easiest path. Possible all right with Express or some other Node frameworks. You have a tone of freedom as far as structure. But you also have enough rope to hang yourself in some cases.

Rails has really good database migration functionality. They allow us to do things like creating and editing tables and columns in our database without having to manually go in and add change things. It also gives you a nice little log or path that you can follow to see exactly what’s been done to the structure of your database.

Now with Node. There are some packages or modules for migrations such as DB-migrate which can work really well, but it’s not as in-depth and easy-to-use as the Rails chord migration system. When it comes to prototyping and rapid development there are not too many technologies out there that can beat rails. So some basic configuration and a couple scaffolding commands you have yourself a full functioning crud application. Database migrations are added to that speed. Node.js and Express are fairly good with fast development if you use third-party tools and modules. But Rails has all that staff right out of the box.

There are some pros and cons to the Ruby language but for the most part, it’s well respected, it’s very clean. Ruby is a multi-paradigm language, you can do procedural code functional, but for the most part, it’s object-oriented. Everything can be looked at as an object. RubyGems is a package manager for Ruby on Rails and it’s used to extend the core functionality of the framework. It’s similar to NPM for Node.js. All rails applications have a gem file where you can specify your gems. Then you can run a bundler command to install all of them, similar to NPM install with Node.js.

Another great thing about Ruby on Rails is that it’s been around for a while and it has a very respected and intelligent community. The developers maintaining Ruby on Rails are extremely smart and very passionate about the framework. There’s a ton of resources on the core framework including forums, blog posts and documentation to help you out if you get stuck. Those are advantages of Ruby on Rails.

Rails Disadvantages

  • Performance
  • Too simple
  • Popularity
  • Lack of documentation

Let’s talk about some of the disadvantages. Some of the biggest complaints that we’ve heard about Ruby on Rails is that it’s relatively slow. Node.js and Express are really fast, but it’s really light. Rails is a big framework with a lot of features in its core. As well as some of the lighter frameworks, you also have the factor in the gem and application file dependencies. There’s so much automation and scaffolding that the developer doesn’t really learn very much about. You may know about the Ruby language, about the syntax or the structure of their application. For someone that really understands how Rails works. This is great because of its rapid development. On the other hand, some of the developers really have to go the extra mile to really understand certain things. Rails is also way more difficult for big projects than small applications. It can have some issues with scaling as well.

So another disadvantage, Rails isn’t so popular as Node.js. At this time Node.js is on the cutting edge of web development and the excitement for Rails has really settled at least. In our opinion, if you are looking for a job we would definitely say learn Node and probably Express. More companies are hiring JS developers than any other language. If this way five years ago Rails or Ruby would be one of top three languages to learn. But these days it’s just as popular. So I briefly mentioned earlier that core Rails framework has some really good documentation and examples, learning simple scaffolding commands and database migration. That’s all fine. However when you try to learn more advanced programming and you’re trying to learn about specific gems, sometimes it feels like looking for a Newton needle in a haystack.

Some pretty big names have used or do use Ruby on Rails in their platform. I don’t’ think you can get much bigger than Twitter. Also, they have moved a lot of their back-end services to Scala and Java due to some scaling issues. But they get used Rails for a long time and me pretty sure they still use it in other aspects of their platform. Shopify) which is a huge e-commerce solution. They use Rails back-end services. Basecamp which is a project management solution. They have said that Rails is the heart and soul of the Basecamp project. The software that runs GitHub was built on Rails. On Erlang Bloomberg uses Ruby on Rails. They actually have a recent job opening for rails position. Let’s see Soundcloud, Hulu which is a popular streaming service was built on Rails. From the beginning Groupon and LivingSocial, SlideShare, Urban dictionary these are all huge names that have used Rails.

Node.js Advantages

  • Extremely popular
  • High performance
  • Acynchronous
  • Very scalable
  • JavaScript front & Backend
  • Flexible file structure
  • NPM and Modules

Now that we looked at Rails, let’s start to look at Node.js. We’ll start with the advantages. One huge plus of Node.js is its extreme popularity. It’s basically the new cutting-edge technology in web development. There’s a very high market demand. It’s extremely popular for startups. There’s a flourishing open-source community around Node and Express framework. Many well-developed modules on NPM when it comes to speed and performance Node knocks Rails right out of the water. Actually, it pretty much knocks anything out of the water. It runs on the Google JavaScript engine which is lightning fast. Node is used to build real-time web applications that almost feel like desktop applications.

Next, Node.js is also asynchronous. This means when a program sends a request to the server, it doesn’t have to wait for the reply. It can continue to execute. Node runs on one single thread as opposed to other languages that send the request. They wait till that request is done, then send the next one and so on. So Node.js is also very scalable and being on a single thread plays a big part in that. Node also works really well with NoSQL databases like MongoDB, which is much more scalable than traditional relational databases like MySQL. Almost all big companies that I read about have shifted to Node.js, they have reported at least a decent rise in productivity.

Another great Node advantage, it uses JavaScript which is widely used with many web stacks. The language on the front-end is different from the back-end and that’s not the case when using Node.js. We’re using JavaScript on the front-end and back-end. There’s a tonne of client-side frameworks that are dominating the industry - React, Angular, View JS. So that’s a huge plus to Node.js. Obviously, JavaScript works well with Jason APIs, which are very popular.

Node.Js and Express or Happy JS, any of these frameworks have a really flexible file structure. They let you construct your applications as you want. You can Jam everything into a single app JS file. If you wanted to have more of a traditional MVC structure, I think there are both good and bad sides to this. But for the most part, if you know what are you doing and you are a good programmer then flexibility is a good thing. Like Ruby gems Node also has its own package manager called NPM or Node package manager. The biggest difference between NPM and Ruby gems is the way that dependencies are managed. With Ruby, dependencies are installed globally. So you have to use bundler and have to kind of manage them on your own. When NPM actually takes care of all that for your modules. They get put into the Node modules folder. Then those modules can also have their own Node modules folder with their own dependencies. NPM modules also seem to have better documentation at least in many experiences.

Node.js Disadvantages

  • Sucks for CPU intensive tasks
  • Inconsistency
  • Newer technology
  • Callback hell
  • Too modular

So we looked at the positives the pros and advantages of Node.js. Now let’s look at some disadvantages. As good as Node is for many crud style applications. It absolutely sucks for applications that are CPU intensive. The reason for this is that whenever it does something that takes a while such as CPU operation. It’ll queue all the incoming requests because it runs on a single thread. Something like apache which has more available threads. It’ll divvy up that CPU time between them. And only IO operations are parallel because they’re executed asynchronously. An example of a CPU intensive task is something like 3d rendering, video encoding, scientific modeling, sorting things like that.

Another complained about Node is that it can be a little inconsistent. Some feel that the API keeps changing at frequent intervals. It’s sometimes not very backward compatible. Not only that, but the structure of an Express application, in general, is very free and flexible. Sometimes it can give developers enough rope to hang themselves.

Rails is very strict, so it’s harder to write bad code. So Node and Express, our new technologies, they’re never than Rails and there are not as many developers working with them. As you know, that have as many years under their belts like you would find a through Ruby on Rails developers. But on the other hand, since Node uses JavaScript most developers learn it really fast because they already know the core language from working with JavaScript. Since Node is asynchronous you’are going to be dealing with a lot of callback functions and they often can bubble up and get into what’s called callback hell. There are solutions to this such as async utilities and using promises. There are a few things that you can do to prevent this. This personally doesn’t bother me but I know that some developers that aren’t used to asynchronous programming have a problem with a lot of callbacks.

Frameworks like Express and Happy JS are very light. This can be a plus, but this also means that any extra functionality needs to come from third-party modules. For instance, templating you have all kinds of options with Node and Express bug handlebars. But you need to install them separately unlike Rails, which you can use as third-party template engines. But it doesn’t have embedded Ruby by default. Expresses and as full-featured is Ruby on Rails which it makes it hard to compare, just Express to Ruby on Rails. That’s why I called Node.js versus Rails. Some big names that have used Node.js are Linkedin, which is right up there with Twitter and Facebook. They actually switch from Ruby on Rails to Node.js quite some time ago. They switched mostly for scaling reasons because Node happens to scale better in most situations.

As you can see both of these back-end options have their pros and cons, but they’re both fantastic technologies. Everything should always evaluate on a case-by-case basis rather than just saying one is better than the other in all situations.

Author:

Dasha, marketing director

Published: September 26, 2017

Time to read: 5 min

Contents: