Node.js vs Ruby on Rails
Unlike most developers, I started with pampering with Node.js, and after that I plunged into Ruby on Rails with the help of the exciting
Rails for Zombies course and then the Ruby on Rails tutorial from
Michael Hartl .
All that is written below is the unscientific comparison of Node.js and Ruby on Rails.
Let's start!
Node.js is NOT a framework!
First of all, Node.js is a low-level routing web server with administrative capabilities, written in Javascript for the purpose of asynchrony and high speed. And from the very beginning of this comparison, Node.js needs some
“friends” in the form of
Express.js and
Mongoose (if, of course, you chose MongoDB as your database). Rails, on the other hand, is a Ruby language framework. Technically, for a fair comparison, we would have to talk here about Node.js vs Thin or Unicorn, not Rails, but we want to develop a full back-end, and not just its engine compartment.
Ruby is a naughty old man with a heart of gold.
Now, when we got rid of conventions, let's talk about the language. Node.js is written entirely in Javascript, while Rails is written in Ruby. And in one and in the second there are pluses and minuses. Javascript plays into the ease of learning the syntax, because many probably already came across it in the front-end (against the inherent Rails
')
:VARIABLE => “--” def func arg = " " VARIABLE do |iterator| Module::Class class Subclass < Class @instance , Perl
and other delights).
However, Ruby can be more compressed and does not require a forest of brackets (coffescript readers, do not strain) to work all their magic. Plus, Ruby (and Rails) is full of super-useful built-in methods that surround everything from dates to lines and arrays.
10.minutes.ago “string”.sqeeze ['array','elements'].include?('array')
Yes, all this can be achieved in Javascript, but it will require some knowledge and custom methods ... or something like
_undercore .
100% Javascript is cool, but it is painfully overvalued.
Having dealt with languages, now you can pay attention to the development of web applications. Node.js draws its asynchronous front-and-back Javascript environment, whereas in Rails you will have to deal with SQL, Ruby and Javascript. Although it would seem a sure advantage - after some study of both, I will write down the uniformity of the language in the category of “
overvalued advantages ”. It's not hard to get into Ruby by reading just a few examples and blog posts. Plus, with Ruby you can almost completely forget about the “noodles from callbacks” that accompanies Javascript due to its non-blocking architecture (which I absolutely recognize as a plus in conditions of high parallelism). And yet, although I don’t want to say this, it is sometimes a good idea to have a predefined syntax for namespaces, classes, and modules.
Rails gives everything you need.
Now we leave aside the language and the accompanying.
Node.js + Express.js provide routing along with controllers, view and helper. However, this toolkit still fades away from Rails.
For analogy, Rails on the background of Node.js + Express.js - like Muji on the background of American Apparel
(two large firms selling clothes and home accessories - translator's note) . Both provide clothing and accessories for the home, but American Apparel’s clothes do not look very reliable, do not always meet your needs, try to look cool with pants, and often don’t look along with other things. On the other hand, Muji obsessively decorates everything in the same style and, at first glance, with the same fabric.
But back to programming.
Rails comes right away with a built-in ecosystem, with full MVC and with a set of useful features, which can only be spoiled during critical kosolapii.
Here are a couple of examples of functions:
url_for and
image_tag .
url_for is a built-in function that will always give the url of the data object given to it (
@products , for example), and
image_tag will always take the correct url of the image from the
asset pipeline .
Of course, all this can be done in Node.js, however, this will require a lot of work with modules and helpers. Plus, in Rails, you don’t have to worry about data models at all. Yes, in the case of Node.js, the Mongoose can help, but even with it, it’s difficult to feel complete control over the data that gives you
Product.find(params[:id])
available everywhere from the application, modules, controllers and view in Rails.
However, it is worth noting that all these chips have a downside. I often understand that I simply “guessed” the right way to do this or that, and almost always miss the best way. And also, when something breaks, it is quite difficult to determine the cause of a breakdown due to cunning special variable names (for example, by gluing the action name + controller name + "_path", you can magically get the helper
new_product_path , which returns the current path to the desired action) .
With Node.js, you see only what you wrote yourself - the distortions are minimal.
Lots of people make and improve modules for Rails.
Next: the ecosystem. Despite the fact that Node.js had a great start with NPM, most of even the most popular packages for various needs have not yet settled dust, and the number of competitors is already breaking records. As a result, I often feel as if trying to glue a broken vase with superglue.
On the Rails side, however, is one of the strongest free library and tool repositories. I also quite like
The Ruby Toolbox , which shows the relative popularity of the tools, breaking them down by functionality. Plus, as I said before, there are a lot of modules that you have to manually type in Node; they go out of the box in Rails. Things like database connectivity, profiling, caching, migrations, data models, pipelines, routing, console commands, testing and more ... Even a favicon is already in place! Of course, all this is trivial, but everything is necessary, and it would be cool not to see all these messages about the conflicts of Node.js modules, which for some reason refuse to communicate with each other before noon.
Above all this is a huge amount of textbooks and examples on Rails, much more than there are on Node.js. One only
Railscasts with his 300+ videos. But it should be borne in mind that Rails is changing rapidly, and many textbooks have already lost relevance, and other tasks received their solutions after the publication of certain articles with a detour. As a result, it has become wise to use Google selectors
< 1 year old
to search for answers to questions about Rails, and to begin this search with
Rails Guides .
Rails has jet-pack enabled. Default.
Finally, suppose you have the same framework, database, modules are configured and everything is fine. Node.js requires much more time to just write everything and collect everything (again due to the inconsistency of third-party plug-ins and the lack of a rigid structure). In Rails, a single command is enough to build a complete RESTful interface.
rails generate scaffold Post name:string title:string content:text
and the necessary controller, view and model will wait in their places.
Often it takes 1 minute versus 1 hour (multiplied by the number of DB entities). This is not such a difficult job, but rather vulnerable to typos, and just a lot of information to remember. I don't always use Rails scaffolds, but for simple prototypes it’s hard to come up with a faster alternative.
Finally…
Node.js is a great set of tools, trendy, fast-growing, high-performance (which is debatable), easy to learn and outperform most other web developer tools. However, he still remains a talented high school star against the God of God in the face of Rails. No offense to Node.js, but who would you choose? If you can overcome the inconvenience associated with the study of Ruby - the choice
is still obvious. Remember: the best tool is the one that allows you to do better and faster work.
PS From the translator:
Of course, it is more correct to compare Rails not with a pure Node, but with any MVC framework based on it. For example, Sails.js . However, this article carries a certain amount of useful information for a novice web developer (which I was), so I allow myself a metaphorical comment.
- Rails is equipped with a huge number of functions and libraries that will make your workplace a reliable and comfortable chopper in the world of web development.
- Node develops in monstrous steps, giving the developer a touch-sensitive, but interesting and fashionable sport bike.
From personal experience, Node.js + Sails.js gave me an easier alternative to Rails for small projects - and that's great. But the reliability and strength of RoR in the condition of developing a serious web application, they have not yet been able to replace, although they catch the soul of the back-end developer.
All read thanks!