Node.js vs. Rails



Hacker News, Reddit, Stack Overflow Stats

  • 3.86K
  • 4.31K
  • 259K
  • 2.37K
  • 1.95K
  • 302K

GitHub Stats

Description

What is Node.js?

Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

What is Rails?

Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

Want advice about which of these to choose?Ask the StackShare community!

Pros

Why do developers choose Node.js?
Why do you like Node.js?

Why do developers choose Rails?
Why do you like Rails?

Cons

What are the cons of using Node.js?
Downsides of Node.js?

What are the cons of using Rails?
Downsides of Rails?

Companies

What companies use Node.js?
4699 companies on StackShare use Node.js
What companies use Rails?
2665 companies on StackShare use Rails

Integrations

What tools integrate with Node.js?
95 tools on StackShare integrate with Node.js
What tools integrate with Rails?
38 tools on StackShare integrate with Rails

What are some alternatives to Node.js and Rails?

  • Android SDK - The Android SDK provides you the API libraries and developer tools necessary to build, test, and debug apps for Android.
  • Django - The Web framework for perfectionists with deadlines
  • Laravel - A PHP Framework For Web Artisans
  • .NET - .NET is a free, cross-platform, open source developer platform for building many different types of applications.

See all alternatives to Node.js

Latest News

Node v6.13.0 (LTS)
Node.js Error Handling – ERR_CONSOLE_WRITABLE_STREAM
Building a realtime polls app with Node.js and Pusher
Rails 5.1.5, parallel testing and more!
Rails 5.1.5 has been released
Rails 5.2.0 and 5.1.5 release candidates, marshaling...


Interest Over Time


Rails vs Node - Help me Decide

Rails, is a server-side web application framework written in Ruby. Rails is a model–view–controller (MVC) framework, providing default structures for a database, a web service, and for web pages. Node.Js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. It uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.

In this post, we’ll objectively look at a few of their differences, strengths and weaknesses to help you decide which, and when to use these technologies.

Community Support

Node The Node.Js community is broad, inclusive, and excited to enable as many users to contribute in whatever way they can. It is worthy to note that Node.Js has a package manager npm which has the largest ecosystem of open source libraries in the world. Node.Js also enjoys the support of the wider JavaScript community network.

As a way of keeping developers in sync, Node.Js has a committee that is directly in charge of global outward-facing community outreach efforts. They also organize local and international meetups and conferences to bring developers together. Node has not been around as much as the likes of Rails and Django, however, it is gaining steady popularity and usage. So far it has received, 54.3k stars, 11.7k repo forks with 2.1k contributions on Github.

Node Github repo

Community Support

Rails Rails have been in existence way longer than Node.Js hence, it has a very broad community support. The vast number of Plugins and Ruby Gems available for Rails has made it one of the most supported web framework available. Given that Rails has been around for a long time, it has a lot of people actively using and contributing. You can get involved with the community online on the Ruby on Rails: Talk mailing list, the Ruby on Rails StackOverflow Q&A tag, or the #rubyonrails IRC channel on Freenode.

As a way of keeping the community spirit high and bringing members together, they also do a yearly RailsConf conference for people to meet and share in real life. So far, Rails has received 41.1k stars, 16.6k repo forks with 3.6k contributions on Github.

Rails Github repo

Pros and Cons

Now, let’s take a look at a few strengths and weaknesses of these technologies and hopefully help you decide which will best suit your needs.

Node.js Pros and Cons

The Pros:

High Market Demand At this time, Node.js is on the cutting edge of web development, and the excitement for Rails has really gone down. More companies are hiring JS developers than any other language. This makes Node almost the most in-demand back-end solution right now. Data from Indeed shows that there 9.4K job postings for Node and 3.3K postings for Rails. TechMagic also shows a graph of Node.Js job trends vs that of Rails.

Comprehensive Node.JS covers everything from HTTP server to templating engine etc. Rails rely on something like Nginx or Apache with mod_rails to work. Moreso, it has the same language on both the client and server side making it even more lucrative and comprehensive. Plesk did a comparison post that further showcases this as well as Codeburst Node.js Cons.

High Performance Because of the fantastic npm modules available to Node.js, and the Chrome’s v8 JavaScript engine, it is vigorously fast. When performance is a factor, Node.js performance better than Rails, more like better than any other web framework as it runs on the Google JavaScript engine which is lightning fast. Moreso, half of the respondents of Node.js 2017 User Survey noticed improved application performance in comparison to other solutions. Also, LinkedIn replaced their back-end mobile infrastructure built on Ruby on Rails with Node.Js some time ago for performance and scalability reasons.

Scalability Because Node is asynchronous and runs on a single thread, it has been found by many companies to be very scalable. As a matter of fact, companies like Twitters new web stack is built on Node.js.

The Cons:

Single CPU Node.Js is bound to a single CPU, and as a result, it is not suitable for processor intensive tasks according to this recent findings on Codeburst.

Unending Frameworks Just like JavaScript, Node.js has tons of frameworks and there’s still more coming every day. This can get a little weary for developers as they will have to constantly learn the new frameworks to stay up to par. According to Pramod on Codeburst, Node.js remains inconsistent with it’s changing API’s but might change for good in time.

Not so backward compatible Because of the inconsistency in Node.Js API’s, it keeps changing at frequent intervals. As a result, it is often not very backward compatible. A statement on the release website just showed that they have made minor changes to support backward-compatibility.

Asynchronous Node is asynchronous. Hence, you’re going to run into a lot of callback functions that can potentially pile up to what is called a callback hell. However, the Node.js community has devised a few ways to prevent this on CypherTrick.

Rails Pros and Cons

The Pros: Consistency Rails is very consistent in it’s development structure given that it follows the MVC pattern. As a result, most, if not all Rails applications will look the same with regards to core files and application structure. According to Mical on NetGuru, Rails still maintain one of the best industry standards.

Development efficiency Rails has an efficient system of modules and a package manager that makes it super easy. It also has tons of gems that could serve for pretty much any purpose. This in turn speeds up development time and increases productivity.

Ease of migration Rails is also one of the very few web frameworks that has a really good database migration functionality. Creating, editing and updating tables and columns in databases can be done directly on Rails without having to change settings on the database manually.

Vibrant community According to Micals RoR community post, Rails has an amazing community of developers who are constantly working to improve Rails by way of addition of new functionalities, creation of guides, attending to issues, etc.

The Cons: Performance One of the major pitfalls of Rails is that it is relatively slow. Both the runtime speed and the boot time speed are all slow as compared to that of their alternatives Node.js and GoLang. As a result, LinkedIn replaced their back-end mobile infrastructure built on Ruby on Rails with Node.Js some time ago for performance and scalability reasons.

Errors are expensive to fix If you’re able to be thorough and pay attention to all the small details during development, Rails will definitely be your helpful friend. However, if you make a wrong architecture decision during development, it could turn into a very expensive ordeal. Rails structural deficiencies are hard to fix because Rails is an open framework, where all components are tightly coupled and depend on each other. For instance, too much reliance on ActiveRecord makes an application logic tightly coupled with database models, which leads to maintainability problems in the long run.

Scaling Rails has been understood to have major scaling issues for big projects. As much as it works well for small applications, once capacity grows and you have need for scaling, it gets generally difficult with Rails. Company’s like Twitter has had to move away from Rails at some point when they faced a major scaling issue.

Strict nature Rails is a very opinionated framework as some will say. It forces you to follow a particular way. Some do see it as a good thing but we understand that flexibility is important not just for the project but for the developers creative skill.

Learning curve

Rails learning curve Rails follows the MVC structure, this makes it easier to understand for developers who are already familiar with the MVC framework. It however makes it a bit more difficult for non MVC experienced developers when trying to quickly get started on Rails. Moreso, it is vast with tons of gems and libraries, it takes quiet some time to get experienced with the framework given the number of tools you’ll need to get familiar with.

Node.Js learning curve Node runs on JavaScript, which according to BusinessInsider is the most popular and in demand language in the world. This alone makes it pretty much easy to use given the fact that almost every developer (even non JavaScript developers) are in certain ways very familiar with JavaScript syntax and concepts. However, it is worthy to note that Node itself is different from JavaScript, but being that it was built with JavaScript, JavaScript developers use it to maintain stack consistency. This however, means that developers coming from non JavaScript backgrounds like (Java, C#, PHP etc) will have to first understand JavaScript in order to efficiently use Node.

Getting started

Getting started with Rails:

  • Step1: Download and install Ruby and SQLite3
  • Step2: Confirm installation by running this command:
    $ ruby -v
    // this should print a value like this
    // ruby 2.3.1p112

Rails require Ruby version 2.2.2 or later.

  • Step3: If you are working on Windows, you should also install the Ruby Installer Development Kit.
  • Step4: Confirm SQLite3 version by running this command:
    $ sqlite3 --version 
  • Step5: Install Rails using the gem installation command:
    $ gem install rails
  • Step6: Verify Rails installation by running this command:
    $ rails --version
  • Step7: Create a new Rails app, switch to it’s folder and start the server:
    //create a new app "newProject"
    $ rails new newProject
    // swicth to the project folder
    $ cd newProject
    // start the server
    $ bin/rails server

Now open a browser window and navigate to localhost:3000. You should see the Rails default information page:

Getting started with Node.Js:

  • Step1: Download and install Node
  • Step2: Confirm Node version:
    $ node -v
  • Step3: Create new Node project, switch to the project folder and open it up in VSCode:
    // create project folder
    $ mkdir newProject
    // switch into the project folder
    $ cd newProject
    // initialize a Node project in it
    $ npm init -y
    // ... next open up the project folder in your editor ... //
    $ code .
  • Step4: Create an app.js file in the project root directory and update it with the code:
    const http = require('http');
    const hostname = '127.0.0.1';
    const port = 3000;

    const server = http.createServer((req, res) => {
      res.statusCode = 200;
      res.setHeader('Content-Type', 'text/plain');
      res.end('Hello World\n');
    });
    server.listen(port, hostname, () => {
      console.log(`Server running at http://${hostname}:${port}/`);
    });
  • Step5: Run the Node app:
    $ node app.js

Now visit localhost:3000 and you will see a message 'Hello Node!!' with this output:

Performance

Performance is a major issue for the Ruby on Rails community. Given that the framework is heavy and embodies a large number of mixins and gems that further contributes to the slow runtime and boot time of Rails applications. As compared with the likes of Node.Js, GoLang and Python, they all outperform Rails given that it has the lowest runtime and boot time speed.

That said, Rails has been making consistent improvements to increase performance. This has kept all the big companies running on Rails afloat without issues till date. On the 16th of September 2018, Daniel J Colson posted on the Rails blog about some major performance improvements some of which are:

  1. Do less work and use less memory - This successfully replaced 1682 system calls with just 14.
  2. Use faster globs for template resolving - This made file storage 1.58% faster, stopped the allocation of arrays on no args etc.

You can also check out the full list of the most recent changes on their Github repo.

Node on the other hand is a JavaScript runtime powered by Chrome v8 JavaScript engine which makes it lightning fast. As a result, Node has one of the fastest runtime and boot time speed. Node.Js also owes its fast performance to the fact that it is single-threaded and asynchronous. This means that every I/O operation doesn’t block other operations. Hence, you can read files, send mails, query the database, etc all at the same time.

Companies and individuals have found their applications to be twice and thrice faster with Node than with other conventional frameworks. However, given that it is single threaded, performance suffers a bit of a downfall during heavy CPU intensive tasks.

image from Techmagic on medium

As can be seen from the table above, Rails has the slowest runtime when compared with the likes of Java and JavaScript.

Community Impact Numbers

These technology are both widely used by developers around the world. We’ll curate the ratings given by users on different platforms as at the time of writing to help you understand how other developers see them:

Platform specific metrics:

Framework Hackernews Pts Reddit Pts StackOverflow Qs Github Stars Stack Jobs
Node 3.86K 3.4K 246K 54.3k 5.21K
Rails 2.37K 1.29K 298K 41.1K 3.95K

According to this Stackshare ratings, 2178 companies on their platform use Rails including twitter, AirBnb and Codecademy. It also integrates with over 39 tools. The same ratings puts Node.Js on 3404 companies and 93 tools.

Conclusion

Node.Js is perfect for web apps, mobile apps, real-time applications (instant messaging, live chat), online gaming apps, e-commerce transaction software, and much more. It's also a good choice if you're dealing with microservice architecture, which can lay the foundation for advanced systems – bear in mind that apps like Netflix or Uber were built using Node.Js.

Rails is definitely one of the best web development frameworks to consider for your next project. With Rails, you can do pretty much the same as with other good frameworks. The excellent community, a quality code base, the sheer size of the module database, and the maintainability of Rails applications made it the preferred choice for such successful projects as Airbnb, GitHub, BaseCamp, Zendesk, and Bloomberg. However, the devil is in the detail. Rails is surely a good choice if your project has tight deadlines and budget requirements.