You’ve got a few (or many) Rails apps under your belt and you’re pretty good at it, but you hear all the cool kids talking about this thing called “Node” and you want try your hand at it. Here’s some advice for getting started and for clearing up some confusion that you might have at first.
Why learn Node and why do others use it?
Let me give you some personal background first. I started getting interested in Node when a major Rails project that I was working on finally came to a close. As I started looking around for the next project to work on, I began to realize that Node, a framework that I was aware existed and was popular, was in fact popular and existed. (Go figure!)
- Although Rails’ performance problems are overblown, Node genuinely shines in many contexts. Maybe if people didn’t abuse ActiveRecord queries so heavily, Rails wouldn’t have such a bad reputation for slow performance. Time has nevertheless shown that Node has excellent performance in concurrency. Performance degrades when it comes to computationally-intensive tasks, but most web apps aren’t computationally-intensive (and if yours is, you should probably refactor out your cancer-crunching algorithms to something like Java and hook in where appropriate). The performance gap makes intuitive sense. The V8 engine at the heart of Node was designed by Google with performance as the primary goal whereas Ruby was conceived by Matz first and foremost as an elegant and pleasant language.
What exactly is Node and what are some important differences from Rails?
Now that we’ve covered why people use Node, it’s time to discuss what exactly we mean when we say Node. I’ve created a table below that compares technologies within the Node and Rails ecosystems:
|Technology||Node world||Rails world|
|Web server||Node||MRI + Unicorn/Puma/WEBrick + Rack|
|Package management||npm||gem + bundler|
|Popular minimalist framework||Express||Sinatra|
|Popular heavyweight framework||Meteor/Sails||Rails|
|Utility script management||Gulp||Rake|
There are a few differences here that merit further discussion:
- Minimalist web frameworks are way more popular in the Node ecosystem. In the world of Ruby-based frameworks, minimalist web frameworks, like Sinatra or Padrino, have always been a bit of a sideshow compared to Rails, which as been the main course. Not so in the Node ecosystem where developers have embraced minimalist frameworks, especially Express. Just compare Google trends (Express vs. Meteor and Rails vs. Sinatra vs. Padrino), GitHub stars (30.3k Meteor/12.7k Sails/21.9k Express and 28.6k Rails/7.5k Sinatra/2.6k Padrino), and StackOverflow tags (17.2k Meteor/3.8k Sails/19k Express and 226.2k Rails/4.3k Sinatra/340 Padrino) to get a sense of the relative popularity of full featured vs. minimalist frameworks in each ecosystem. When starting to learn Node, therefore, it behooves you to consider learning a minimalist framework like Express.
In sum, just learning Node by itself won’t get you very far when it comes to becoming a Node developer. You’ll need to learn at least one web framework. You’ll also need to change some of the ways that you think about architecting your web apps, especially when it comes to thinking beyond the classical MVC pattern.
What will I need to learn in order to become a Node developer?
I am by no means the most qualified person to answer this question since I’ve just started my journey into Node, and what follows stems from my limited experience.
- Node itself. This suggestion might strike you as a little strange since most novice and intermediate Rails developers don’t make a point of learning Rack/Ruby web servers properly. The difference is that whereas Rails generally isolates the developer from the underlying Rack API’s, Node-based apps tend to interact with the underlying Node API’s much more frequently, so you’ll need to learn Node proper early on.
- A Node-based web framework. Personally, I recommend learning Express first. Express has a very concise, Sinatra-inspired API, and if you’ve ever made a minimalist web app using Rails, Sinatra, or something similar, you’ll find yourself right at home. You can master Express after developing a few toy apps, and unlike learning Sinatra, mastering Express will place you in the mainstream of the developer community with highly-demanded skills.
- Node-related tooling. This step is pretty straightforward, and you’ll be able to pick up tooling skills as you go along. The only thing to realize is that in the Node ecosystem, the tooling options are much more varied and generally aren’t just provided to you as part of the framework. I recommend becoming familiar with gulp, which is the Node world’s answer to Rake, in particular.
- New patterns and ways of thinking. Closely related to the first step listed above, you’ll need to become familiar with new paradigms and idioms. I’d like to cover some of these in a subsequent post, but for now let me list a few that I’ve found to be the most confusing when coming from Rails: no MVC, asynchronous execution, prototypal inheritance, and binding/scope.
OK, enough chit chat. What’s the best way to actually start learning Node development?
I would start from the beginning of the beginner book and work your way through the craftsman book, but I would skip the chapters in the craftsman book on MySQL and MongoDB and revisit them later if you want to use those systems. I suggest skipping those chapters because, in my experience, creating toy apps doesn’t require an in-depth knowledge of database client libraries, and you can get by with just cribbing code from the libraries’ GitHub pages and API docs. I would also skip part 2 of the craftsman book, where you learn how to create a complete AngularJS web app with Node, because you’ll cover similar information when you learn one of the Node frameworks.
After working your way through Kiesseling’s books, I’d learn the Express web framework by working through their getting started tutorial first and then their guide. You can easily master Express through just these resources if you’ve developed web API’s before as the API is very concise.
Having learned these concepts and technologies, you’ll be well on your way to becoming a Node developer!
Stretch goals: React