Learning Node.js

imageI’ve been learning a new programming language the last few months, for the first time since the summer of 2009 when I spent a few months dabbling in Python. This time it’s Node.js, the popular new environment for writing high-performance internet applications and web servers.

If you’ve not heard of Node (I’m looking at you, Mom), you’ll probably want to stop reading at this point and go look at pictures of our dogs instead.

Node didn’t feel 100% new to me, because it’s essentially server-side JavaScript, and I’ve copied and pasted my fair share of JavaScript over the years. (As Douglas Crockford has observed, JavaScript is a programming language that people tend to use without bothering to learn it first.) But the details of the language are just part of what it means to learn Node. Like all programming languages, Node is both a well-defined set of syntax constraints and APIs and a nebulous philosophy with a gestalt that you need to understand to get the most out of it.

Here are a few of the resources that I’ve found useful for learning about both the syntactical and philosophical aspects of Node …

First off, if you don’t already have it you’ll need to install Node. You can find all the latest versions and instructions for the (extremely simple) installation process on the Nodejs.org web site. A note for Windows users: if you see references to running Node under Cygwin, that’s the old unsupported approach. Now you can simply install Windows binaries from Nodejs.org, no Cygwin required.

If you don’t know JavaScript, or are new to programming in general, check out the online book Eloquent JavaScript, a well-written overview of JavaScript programming.

An important resource to know about is the documentation on Nodejs.org. Documentation is available for many different releases, and you can see all of the versions on this page. Note the link at the top of that page to the latest version. That’s what you want if you’re new to Node, and you need to be careful when you follow links that other people provide to documentation of Node APIs. Some people have hard-coded links to specific versions of the documentation (I’ve seen a link to version 0.6.0, for example), and you can waste a lot of time trying to debug code running in version X while you’re referring to documentation of an incompatible version Y. As long as the URL has docs/latest in it, you can be sure you’re looking at the documentation for the current release.

imageAfter you have Node installed and know how to look things up in the documentation, it’s time to learn a bit about how to use this shiny new tool in your toolbox. Node is great for some things (real-time web apps, single-page apps), but it’s not for everything. You can find on Youtube a good video overview from Ryan Dahl, the inventor of Node.js, that can help you understand the thinking behind Node. Mikeal Rogers also has a well-known post on “The Way of Node” that outlines a set of guiding principles for Node developers. Another outstanding resource is HowToNode.org, which is run by Tim Caswell, community manager at Cloud9.

In all programming languages, developers eventually find a huge number of stylistic details to debate, and Node/JavaScript is no exception. Felix Geisendörfer, one of the early core contributors to Node, has written up a set of Node style guidelines that are the defacto standard. You should also run your Node code through Douglas Crockford’s JSLint, an online “code quality checker.”  JSLint is very opinionated, and may hurt your feelings – it’s up to you how much of its advice to accept or reject. Crockford’s book “JavaScript: The Good Parts” covers the philosophy that is embodied in JSLint, and is well worth reading and re-reading. Crockford’s approach reminds me of the old saw about how programmers optimize first for code size, then for performance, and then for maintainability – Crockford is most definitely in the “optimize for maintenance” phase of his career.

Finally, one other resource is not free, but I’ve found well worth more than the $7.99 cost: the Node.js Bundle from LeanBundle. Both books are provided in PDF and Kindle format.

For an old-timer like me (let’s just say I still remember the buzz of Fortran-77 being the shiny new programming language), there are some things to instantly love about Node. Installation is fast and simple (and free), and the Node interpreter is a single executable that you can fire up and immediately start typing statements in a command window (or REPL). You can also type Node myprogram.js at your OS’s command prompt to run your masterpiece. I have Node installed on my Windows, Mac and Linux machines, and the development experience is roughly the same on all three. Well, different text editors of course, but that’s a whole other area of passionate disagreement among developers so let’s not go there today.

I have asserted here that Node is fun. I’ll try to back that up with a few simple code samples in my next post.

3 thoughts on “Learning Node.js

  1. Tom Kepler

    Wow, it’s like mahugh.com is being written just for me these days. :)

    Thanks for the linkies — I’ll be doing quite a bit of reading in preparation for some nerding when you get back from the UK.

  2. Pingback: Learning Node.js | javascript node.js | Scoop.it

Comments are closed.