Ruby on Rails and Full-stack JavaScript

Written by ajay.ns08 | Published 2017/12/08
Tech Story Tags: ruby-on-rails | javascript | web-development | fullstack-javascript | software-development

TLDRvia the TL;DR App

Recently, for a project I had to work on, I shifted from my regular routine of npm install to an entirely different stack built on a different language. Let me tell you this, it’s not hard as it sounds as, the more I worked on it, the easier and more familiar it became. This article could probably help out as a tutorial also, if you are planning to get started with RoR and have experience with full-stack JavaScript. So below are a few basic things you’d notice switching between these two stacks.

The Similarities

Starting with NodeJS and NPM, a MEAN Stack project would include a package.json, which lists all the npm packages that are dependencies for the project. So basically, to setup a local development env, you run npm install and all the required packages gets magically saved into a folder called node_modules in the project directory. This process is automated by JS frameworks with CLIs such as Angular, which sets up an application structure and installs all the required dependencies.

Ruby on Rails follows this exact same concept for setting up. The Rails equivalents for npm packages, package.json and npm are Rubygems (commonly referred to as gems), Gemfile and bundler respectively. And Rails CLI by itself has a commands to setup a barebones application structure which also installs the gems, and sets up a basic database, for rapid development.

// Angular CLI
ng new <project-name>

// Install package using NPM
npm install <package-name>


// Rails CLI
rails new <project-name>

// Install Rubygem
gem install <gem-name>

// Install all packages in Gemfile (Something like npm install)
bundler install

These similarities are not only just for project setup but also for running them. Ruby also comes with integrated full-stack which doesn’t require separate setup with frameworks such as ExpressJS for NodeJS and to ease things out even more it ships directly with a simple PostgreSQL database.

// Starting up a MEAN application with Node
npm start

// If the application is built over a CLI such as Angular
ng serve

// Starting up a Ruby on Rails application
rails serve

The Differences

Primary difference you notice in package management is that there are no global and local packages like in NPM, which uses this method to prevent version conflicts as different projects may require different versions of the same package. Ruby on the other hand runs smooth with all it’s gems being installed globally and taken care of by bundler. Basically it has no local equivalent to node_modules and installs the packages system-wide to be shared by all your projects.

Another thing would be embedded Ruby files (.erb), which is Rails’ answer to web components and directives which are implemented using React or Angular in a JavaScript stack. This templating system is very similar to Twig in PHP.

Talking about databases, NodeJS uses npm packages which acts as an interface or driver to connect to MongoDB, MySQL or so. RoR already comes with PostgreSQL by default, with capabilities to work directly with it from the CLI as well an web GUI interface.

The Conclusion

I don’t think I need to actually say it out loud at this point, it’s pretty clear that albeit the differences, switching between both is pretty easy, as concept wise it’s a lot similar.

Hope you liked this article. If you did, please be sure to recommend, follow, and share. By the way, I’m on twitter and github :)


Published by HackerNoon on 2017/12/08