Rails vs NodeJS — the comparison

Jibin Mathews
The Bit Theories
Published in
4 min readOct 15, 2016

--

source :https://bsdmag.org

There are thousands of articles on the web regarding these three words. So why am I writing about this?

Answer: None of the answers could satisfy me.

I have worked with NodeJS as well as RoR and implemented the same server using both the technology stacks. So, here are some pros of both the stacks.

Lets clear something first (And hard code this in your brain’s neural net)

NodeJS is a Runtime Environment for running JavaScript as a server.
Rails is a Framework for Ruby Language.

Pros of NodeJS

NodeJS is blazing fast.

You can see this line everywhere on the web. Literally everywhere. So here too. Why? Because it just is. It is really fast for what it is intended for.

1. Learning Curve

As the name suggests, codes in NodeJS are written in JavaScript. Hence, for those with prior experience in front-end development can easily learn NodeJS. It is easier to write code even for those who are coming from C/C++ or JAVA background.

Rails is similar to python, it has no brackets or semi-colons which many C++/Java developers are uncomfortable with.

2. Flexible project structure

Rails wants a definite file and folder structure. Its architecture is such that it looks for file in particular locations only. It is like all our Mothers. They need to have their items exactly in the places where they wants. Move any file from one directory to another and rails go HAVOC.

NodeJS, on the other hand, is very flexible — You can put all your code in just one file or in many directories. Its completely upto you how you want to manage it.

3. No strict filenames

One problem with Rails is that changing a filename will crash the server. Suppose there is a controller for ‘User’ model in your project, Rails will name the controller file as user_controller.rb . Now if you change this file name, Rails will crash. This is because it implicitly imports files by looking up filenames based on its internal logic.

NodeJS on the other hand has no such limitations. You can name your files user_controller.js or userController.js or UC.js or u_controller.js or anything else. NodeJS is cool with it. You just need to require the files wherever you need to use them.

Pros of Rails

1. Multi threaded

Ruby is multi-threaded in its operations in contrast to NodeJS which makes it much better for CPU intensive operations.

NodeJS is single threaded and was designed for heavy I/O bound applications and is great in this domain. BUT when it comes to heavy computing requirements, NodeJS is terrible.

2. No callbacks

In ruby, all the instructions are executed sequentially. i.e the processor waits for the result of the current line operation before jumping over to the next line. This makes ruby a good scripting language.

NodeJS functions asynchronously. For most of the programmers coming from any other language, callbacks are something from the dark world.

3. Code Maintenance

Ruby on Rails follows coding conventions that make them simple to go from one developer to the next. Your hair will be thankful, as you’ll no longer be pulling it.

NodeJS can be tricky. You can put your code in any file you want which can create problems when handing over your code to some other developer.

Bonus Comparisons of different back-end technologies:

No. of concurrent clients that can be handled, Source: hachrocket.com
Memory usage by web server in different languages, Source: hachrocket.com

As evident from the graphs, there is a tradeoff between the ease to code and performance of server.

Module count comparision of NodeJS vs Rails, Source: http://www.modulecounts.com/

Also from the module count graph above, we can see that NodeJS has more modules than Rails. The community support NodeJS modules has increased exponentially.

Takeaways

  1. Why we should use NodeJS.
  2. Why we should use Ruby on Rails.

Rails is for CPU intensive operations WHILE NodeJS is for IO intensive operations.

Don’t forget to Recommend & Share :)

Please click the “Follow” button to learn easily via “The Bit Theories

Team Cyber Labs (Website, Facebook)

--

--