Blog

Websockets and More: 20 awesome node.js npm modules we use every day

April 17, 2012 8:17 am / by / 16 comments

Strider, our continuous deployment platform for node.js and Python, is in fact written in node.js and Python and it was the first project that we started testing and deploying via Strider. Yes, we are in fact continuously deploying Strider via Strider itself. It’s our own small attempt to bootstrap the Singularity. (Continuous deployment means that we automatically test after every commit, and then immediately deploy that code to production if the tests pass.)

So anyway. We use node.js for our web application server (along with backbone.js on the client), and the workers (which run the actual tests) are written in Python. While node.js is best known for its real-time capabilities with websockets, it is very easy at this point to build your entire web app in node.js. Node.js has a great package manager in npm and a strong ecosystem of modules. One of our biggest challenges was figuring out which modules would work best. Here’s what we chose:

Web Framework: Express is our node.js web framework of choice. Express is built on top of Connect, the definitive middleware framework for node.js.

Templating: Jade is the favored templating engine of the Express.js core team and it is also our favorite. After using jade for a while, it now actually pains me whenever I need to fully type out html. The amount of typing that jade eliminates dwarfs that involved in the recent (ongoing?) semicolon debate.

Auth: Everyauth integrates tightly with Express and provides excellent authentication and authorization support both internally and against a long list of external services. To date, we have only used it for internal auth and for oauth against github.

Database: We use MongoDB as our primary datastore. To connect to MongoDB, we use Mongoose as well as Mongoose-Auth for Everyauth/MongoDB integration. This combination has worked well although it is less than ideal that every data object comes out of the auth module.

Session Store: We use connect-mongo as our session store.

Email: We send outgoing email via Sendgrid and took their recommendation to use the node_mailer module. It hasn’t been updated in a while but has worked well for us so far.

Control-Flow: Step has proven very useful in certain situations. For example, since MongoDB has limited joins within the db, on occasion we may need to execute one query, and then upon receiving the result, execute a sequence of additional queries to perform a ‘software join’. Step significantly simplified the code required for this flow.

Testing: We use a number of modules for testing, including mock-request for mocking req/res pairs, Sinon.JS for other stubs and mocks, sanboxed-module for dependency injection, and should.js for assertions. Niall’s recent blog post talks about the testing modules in a bit more depth, and in a future post we will walk through an example app that uses all of them.

Logging: We send our logs to loggly and store them locally. We patched console.log/debug/warn/error to go into Winston at equiv levels.

HTTP Request: Request is the gold standard HTTP client for node.

Password Hashing: Bcrypt of course.

Websockets: Everyone uses socket.io and for good reason.

String Validation: We use node-validator to validate email addresses and whatnot.

Other Libraries:

  • Humane Dates is very helpful for more readable dates – “2 hours ago” or “5 days ago” instead of just the raw date.
  • Nibbler encodes and decodes our invite codes to and from base32.

That’s it for us. Have a favorite node.js module that isn’t on our list? Let us know in the comments.

Tags

 
  • http://jaredhanson.net jaredhanson

    Thanks for publishing this list.  Always helpful to see what other people have settled on.  In regard to the less-than-ideal situation you mention surrounding mongoose-auth and everyauth, I’d encourage you to take a look at Passport (http://passportjs.org), which I’m the author of.  It solves a lot of the frustrations I had with existing Node.js auth solutions.

    Raquel Vélez has written a nice article describing the transition:
    http://raquelvelez.com/blog/2012/03/transitioning-from-mongoose-auth-to-passport/

    • http://blog.marfalkov.com/ Marfalkov

      Yeahh, Passport is the way to go!

  • David

    I miss only node-cron. It’s perfect to call external services at a planned time.

  • Madhusudhan Srinivasa

    woah! Its the same stack I use everyday! except for the testing one and postmarkapp for emails

    • Anonymous

      What are you using for testing? Very interested to hear which frameworks or tools people are using for testing in Node.JS!

    • Niall O’Higgins

      What are you using for testing? Very interested to hear which frameworks or tools people are using for testing in Node.JS!

      • Madhusudhan Srinivasa

        I am using mocha, vows and sometimes nodeunit. I should really checkout passportjs, been using mongoose-auth and everyauth for a while now but its support is very slow.

        • Niall O’Higgins

          What are your thoughts of vows compared with mocha/nodeunit?

          • Madhusudhan Srinivasa

            Its quite complex to write deeply nested async tests using vows, that way mocha is too flexible, it also runs on the browser. I mostly use mocha these days… 

  • http://trevoro.ca/blog trevoro

    For Logging I’ve been using Bunyan and it’s pretty awesome.
    https://github.com/trentm/node-bunyan

    • Niall O’Higgins

      Bunyan looks nice, although would love pluggable output formatters in addition to JSON.

  • JCBarry

    For testing make sure to check out visionmedia’s Mocha: 
    http://visionmedia.github.com/mocha/

    • http://niallohiggins.com/ Niall O’Higgins

      We are actually using Mocha for testing. Our testing setup is described in this blog post: Niall’s recent blog post

  • Samyak Bhuta

    I have used node-http-proxy for various reverse proxy needs ! It is excellent module and serves the purpose !

  • Philippe Modard

    Great!  Happy to see that I use almost the same stack!!

    But for session store, I prefer connect-redis, as redis is really good for this kind of use.
    And for the control-flow, I use async (https://github.com/caolan/async) instead of Step.