Ruby on Rails vs. Node.js & Express

I wrote my first Node app, with Express, a few months ago. At the time it seemed very similar to the process I would normally go through when building a Rails app, with more dials to configure. Rails is famous for the saying: Convention over configuration and it was through building this Node.js app that I truly came to appreciate that proverb. I wanted to dig around and appreciate some of the differences between Node.js and Rails to better understand when it may be appropriate to use one over the other.

A couple house keeping things to consider before we go dive in. It’s important to note that both of these tools are server-side technologies that work with separate languages. Rails works with Ruby and Node.js works with Javascript. Node.js is the feather-weight in the ring, as it doesn’t make any assumptions about how you want to configure your application — e.g. you have to set up the port that the web server will run on, whereas in Rails this is done for you. Lastly, keep in mind, Rails is hard MVC and Node.js allows for MVC with Express.

Rails: Advantages

Rails contains a consistent structure, using the MVC architecture exclusively. The core files and folders are going to look very similar project-to-project. Rails is very opinionated. It assumes you are going to write code a particular way. The major advantages to this approach is that it makes errors easier to spot and understand; makes for cleaner code; it’s easier to write and read. A morbid, but accurate, way to think about Rails is that it limits the rope you can use to hang yourself. While other frameworks offer less opinions about how to interact with them, they often invite problems you can all together avoid with Rails. An example of this was when I was setting up a Node.js app with MongoDB, just to get the database talking with the application was a hassle, whereas in Rails it comes by default with Postgres, making it much more streamlined and easy. Rails has great database migration and functionality for editing and creating columns in our database without having to manually go in and add or change attributes. With that said, Node does have packages, such as db-migrate, but it is not as easy to use and doesn’t offer as much as compared to what comes standard on a given Rails application. When it comes to prototyping and rapid development Rails is hard to beat. You can CRUD full applications with a few scaffold and configuration commands. Database migrations are a big contributing component of this efficiency. Node and Express can also be fast, but again requires more configuration to provide the same functionality that Rails does out of the box.

The Ruby language itself is great. It is very expressive, making it easier to read relative to other languages. This contributes as another factor for speeding up development, as a lot of Ruby frankly looks like plain English. It has tons of helpful methods built into the language that make it easier to write than many other languages. Lastly, RubyGems is Rails package management tool, used to extend the core functionality of the framework. Since the Rails ecosystem has reached maturity, there are tons of helpful gems that keep us from having to reinvent the wheel in our applications — e.g. Devise for user authentication and authorization.

Rails: Disadvantages

Rails is relatively slow compared to Node and Express. Rails comes out of the box with a lot of things we may not even need in our application. At Rails Conf 2017, I heard a talk by DHH, the founder of Rails, in which he talks about understanding the community’s frustration with having so many tools that go unused in Rails projects, and contribute to slowing down the application. Rails automates so much for us that a beginner developer who starts with Rails is at high risk for not actually understanding how it works. Rails abstracts away so much for us that we don’t need to think critically about components that otherwise might be considered in depth with another framework. Working with Rails on big projects comes with its own set of headaches and can have issues scaling as a user base grows. With that said, here are some companies that use Rails: Hulu, Groupon, Urban Dictionary, Soundcloud, Bloomberg, Basecamp (founded by DHH), Shopify, and Living Social. Twitter did use Rails for a long time, but has since made the transition to Java and Scala.

Node.js: Advantages

Node.js is extremely popular at the moment, with a growing community of developers and lots of jobs! Node knocks Rails out of the water with performance. Running on the Chrome V8 Engine, Node is used to build real-time applications that run as smoothly as desktop applications. It is asynchronous, meaning it doesn’t need to wait for a request cycle to complete before continuing to run the application. Node is highly scalable and being on a single thread plays a big part in this. Node plays nice with non-relational databases as well, which are much more scalable than traditional relational databases like PostgreSQL. The biggest advantage of Node is that the language used on the backend is the same as what gets used on the frontend — i.e. Javascript! That is very uncommon among most frameworks. Furthermore, Javascript works easily with JSON (Javascript Object Notation) API’s, which are very popular. Node and Express, have a very flexible file structure. We as the developer retain total freedom for how we want our application to be setup. Again, this offers room to make our lives more difficult for ourselves than otherwise would be with something like Rails, but for the most part, if you know what you’re doing as a developer, then flexibility to desirable. NPM is Node’s package management tool and makes it so instead of globally installing libraries on our machine, by default it saves the libraries packages to our project inside the Node Modules folder.

Node.js: Disadvantages

Node sucks for CPU intensive tasks — e.g. sorting, scientific modeling, video encoding, 3D rendering. Node can be inconsistent, making it not very backward compatible. The freedom of being able to set up our applications however we want serves as a double edged sword as mentioned, making it more likely for us to cause undesirable pain points that may very well have been avoided all together with the use of Rails. Since Node is asynchronous, resulting in the use of a lot of callback functions — often referred to as ‘Callback Hell’. However, we can avoid this through the use of promises in our Javascript. Lastly, we need to configure way more in Node, to get our applications to a level that we could otherwise take for granted when using Rails. This might be considered a positive, however, in that it demands we have deeper understanding of each component working within our application. Some big names that use Node.js include: LinkedIn, Ebay, Ancestory, Yahoo, PayPal, and yup, Medium.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.