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 Socket.io 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?
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.
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.