How I am switching to Node.js

Matthew Nuzum —  — 5 Comments

In the last blog post I explained that I was moving to Node.js from Django and what is motivating me to do so. So how am I making the switch to Node? This post answers that question.

I love to read so I’ve got two books to share with you, and then I’ll identify three tasks that are well suited to Node.js which you can choose from for your to get started. First let me share the books I read and found helpful.

note: This is part two of three, stay tuned for the final installment.

The first is “Node for front-end developers”  by Garaan Means. This is a very short book and quickly walks you through the process of shifting your thinking from classic web dev to modern Node development. It is not an essential book and not a detailed reference, but it was helpful for me to make the mental shift. As I write this, the kindle edition version is only $5.

A more thorough book that I will strongly recommend is “Learning Node” by Shelley Powers. This essential reference walks you through installing it, learning NPM, creating non-web apps, creating services, using Connect and Express to create web apps, using for real-time push and even unit testing your apps. It also demonstrates several database engines, including key/value stores like Redis, Document stores like MongoDB and traditional RDBMSs like MySQL. After reading the book you will have a high level of confidence in the skills you need to build apps.

Another way to learn is to start using it. One beautiful aspect of Node is that it can be used for more than just web development. This allows you to gradually introduce it into your workflow in whatever capacity it is most immediately useful. So what kinds of tasks is it good at?

Shell scripting with Javascript – there are numerous modules that allow us to script key aspects to repetitive os/build/maintenance tasks. As a matter of fact, using a tool such as Grunt, we can ease  into this very gently. It is a Make or Ant like build tool written in Javascript. It can compress your JS and CSS files as well as do many other tasks with little effort. Getting started is a piece of cake by mixing pre-made ingredients into a recipe suitable for your project. From there it is easy to branch out to make both Grunt and Node do more complex and powerful functionality.

Network services and background processes – Node.js has phenomenally robust and fast socket support. With the Connect module you can build a feature-rich proxy server in about 10 lines of code. (see the “Learning Node” book reference below for a tutorial) I mention network services not because this is a feature that directly attracted me to Node but because it enables easy local development without a web server.

Web development – this is where I’m focusing most of my energy. My stack includes Express + Hogan.js and MongoDB with the Mongoose adapter. With Mongoose you get a database interface that feels very much like a good ORM from Django or Rails. If you want “MVC” you can drop Backbone.js into Node quite easily, though I don’t think you should go that route at the onset. Embrace event driven development as quickly as you can.

Installing Node.js

Whichever of these tasks is the right goal for you to get started with, the first challenge you’re going to face is getting Node installed. I’ve found that it is a very easy install in Windows, Linux (Ubuntu) and Mac OS, but interestingly, Windows was the easiest.

For Windows users you have two choices, install system wide using an installer or simply download the executable. I really like the executable option but the installer is definitely easier to work with in the short run.

For Mac OS users you have the same two choices and one additional option. The additional option is to install with Homebrew, if you have it. To instal Homebrew you need the Mac OS development tools which can be obtained by downloading XCode and then going to preferences, downloads and installing the command line tools. Once Homebrew is installed, from the terminal type: brew install node. Homebrew is the way to go if you’re willing to get the Mac OS dev tools installed.

For Linux users you can install it from your package manager using the default system packages, but you’re guaranteed to get something less than the latest version. However, there are numerous projects that enable you to use packages and keep up to date. Like Windows and Mac, there is a standard installation option available from the Node.js website. I’d suggest using a package manager solution if you have it available.

One more post to go, I’ll be writing that up this week some comparisons between Node and other tools as well as discussing deployment a little bit more.

If it helped, please share!Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+

Matthew Nuzum

Posts Twitter Facebook

Web guy, big thinker, loves to talk and write. Front end web, mobile and UX developer for John Deere ISG. My projects: @dsmwebgeeks @tekrs @squaretap ✝
  • Andrey

    nice piece, thanks. waiting for the 3rd part

  • Arun Neelakandan

    Thanks for the write-up (and the series)! They’ve been quite useful, especially as I hail from a Django background.

  • GreenLinux

    The do you think a good path is : Javascript + Node.js instead of Python + DJango?

    • newz2000

      Well, it depends on what you want. I use Python+Django and JS+Node.js+Express. If all you want is a RESTful web service then it doesn’t matter much which you choose. If you want stuff like a built in admin interface and a lot of the conveniences of a mature product, Django might be better. For me, I like Javascript so I am choosing Node.js + Express for new work.

  • Faron

    Rails, Django, Python, REST on rail, and others languages you have compared and discussed – I am curious about Java? I have limited experience in that area, but from readings and researches, it is apparent that node.js now do have features and such that delivers same as much as java? Looking forward to hear your thoughts on this one.