Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@stevekinney
Created October 30, 2013 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevekinney/7239038 to your computer and use it in GitHub Desktop.
Save stevekinney/7239038 to your computer and use it in GitHub Desktop.
A list of Node resources for @jsoma.

NPM is one of the best features of the Node.js ecosystem. It's like someone went in an fixed everything that annoyed me about RubyGems.

Nodejitsu published some awesome cheat sheets for NPM and package.json that I refer to often.

It's probably worth skimming through Max Ogden's Art of Node. There is also a series of interactive tutorials—kind of like "Try Ruby" that you can download and install at Nodeschool.io.

Since you're coming from a Ruby background, you might want to check out Express, Jade, and Stylus. I'm primarily recommending these three libraries because they are inspired by Sinatra, HAML, and SASS respectively. Playing around with Express is a good way to leverage your familiarity with Sinatra as you get the hang of some of the different patterns in Node.

TJ Holowaychuk—the creator of Express, Stylus, and Jade—also collaborated with some other folks on Manning's Node in Action, which takes you through the above libraries as well as Socket.io in a step-by-step fashion. This book really helped me get a better understanding of Node and I plan on re-reading it in the near future.

You probably have some experience with callbacks and event emitters on the client side. Node also relies heavily on streams—particularly the new Streams2 API. Callbacks are pretty straight forward and you could build a pretty complex web application using them exclusively, but it's when you wrap your head around event emitters and—particularly—streams that Node really begins to click. I tend to use streams for functional programming a lot—a lot like you would chain methods on a single object, actually. You pop a Readable Stream on at the beginning, some Transform Streams in the middle, and then a Writable Stream on the end to pop out your final result.

Underscore.js (or Lo-Dash for that matter) has an amazing set of utility functions, but it has one major drawback: it's synchronous. In many cases, this isn't exactly a deal breaker (it's still the most relied upon module in all of NPM), but occasionally you'll find yourself working with an asynchronous workflow and Underscore isn't exactly working out.

Also, there is the issue of callback hell or "pyramid code". Basically, this is when your callbacks get out of control and things become a confusing mess. One solution is to modularize your code better. Another alternative is to use a the Async library, which overs a number of useful patterns for handling asynchronous code. It's also a good replacement for when Underscore isn't appropriate.

Another asynchronous workflow alternative is to use promises. I don't have a lot of experience with promises, but from what I have read, they look pretty smart. Q is the library you'd definitely want to check out if you're interested in exploring promises. Here is a guide on using Q.

Some other useful libraries:

  • optimist makes it easy to build command-line tools using Node. I have also heard good things about commander, but I have never used it.
  • request lets you easily fire off HTTP requests from your Node app.
  • browserify allows you to package up your Node modules for client-side use.
  • johnny-five lets you interface with Arduino microcontrollers.
  • passport is a library for dealing with OAuth, because OAuth sucks.
  • levelup is a Node driver for LevelDB, which has a large fan base in the Node community. It stores everything in a file on disk like SQLite but it's super fast and based on Google's Big Table.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment