Posted on June 9, 2015 by Chris Harrington

Clean promise chains using a pipeline

A few months ago, I started working on a project with a friend of mine who turned me on to the idea of channeling various asynchronous tasks into a pipeline. The idea is that, instead of polluting your local function with a bunch of .thens, you put each of them into a separate module, and then require them into a unifying function that does all the heavy lifting for you. I’m going to walkthrough my implementation of just that right now in a quick Node JS application.

Continue reading

Posted on June 18, 2014 by Chris Harrington

Setting up a Node web server on an Amazon EC2 instance

Up until recently, I’d been hosting Leaf on Heroku. I had a pretty good experience with Heroku and would recommend it to anyone whole heartedly, especially if you’re just getting into the Node space and want to play around a little. It has a free sandbox plan, it’s really easy to get started. That said, however, when you’re getting a little more serious, the cost of Heroku’s offering is almost twice as much as what Amazon offers. Prices today sit at $34.50 for two “drones”, which are the equivalent of two EC2 instances, while the EC2 instances themselves can be purchased for as little as $9 a month (or $18 for two instances). On top of the price difference, EC2 instances have the benefit of being almost 100% configurable, so I can poke around and do however I please.

From here on out, I’ll assume the reader is familiar with Amazon Web Services and have already spun up an EC2 instance with SSH capabilities. I’m using an Amazon Linux instance, but any of the *nix based instances will do the trick.

Continue reading

Posted on April 15, 2014 by Chris Harrington

Stubbing included functions with Sinon while unit testing in Node

I’ve recently been on a unit testing bender with Leaf; I was able to get to 100% code coverage. I understand that while I might have 100% coverage, I might also have shitty tests, but I feel the inverse is also true: if I have 0% coverage, I most definitely have shitty tests. Either way, I ran into a few hurdles while writing all of these unit tests and I’d like to share how I got around one of them in particular. Most of the libraries that I require in Leaf expose a number of methods for me to use, which is great, because they’re easy to stub using Sinon, as such:

var getStub = sinon.stub(obj, "get");

Continue reading

Posted on April 10, 2014 by Chris Harrington

Securing configuration files with Node for Travis and Heroku

I’ve recently been building an issue tracker using Node called Leaf. It’s a fun project that lets me dive into Node and learn its pros and cons. It uses a number of services that require either API keys or username/password combinations and I ran into the problem of how to secure these sensitive bits of information so that anyone browsing my Github repository wouldn’t be able to sign into those accounts for nefarious purposes.

Leaf is using a couple of different services. It uses Travis for continuous integration and Heroku for scalable hosting (both are excellent, by the way). The convention for configuration variables in Node is to use environment variables, which means that for every environment that builds and runs the application, we have to set the environment variables that correspond to each of our configuration variables. It’s quite the pain in the ass. I’ve broken down this post into three sections, one each for setting the appropriate environment variables locally, for Travis and for Heroku.

Continue reading