Proxigram – a sprint using Node.js, Express.js, & the Instagram API

I’m happy to share a little experiment I played with this week. I needed to take a look at Node.js & it’s family of technology for a project but found it hard to find good explanations of best practices, etc. There are a half-dozen competing boilerplate/template samples that have very little in the way of explanation or comments. So, I decided the best way to get familiar with the nitty gritty of building a Node/Express app was to write one.

I decided to solve a simple problem I had. I wanted to get my recent photos from Instagram onto my blog. I wanted it to be a simple JS call or plugin, and I wanted it to be smart about storing keys for read-only access to my Instagram account. It seemed like a simple proxy for the Instagram API would suffice. The OAuth credentials are stored on the proxy and a new, non-Instagram specific key gets embedded in the JS.

And thus, Proxigram was born.

Sure, it’s a little contrived, but now that I’ve built it, I’ve got ideas for some improvements and, even better, I now have a functional, real app to share with everyone so I can get feedback about all the things I did poorly.

The source code is all on Github, both for Proxigram itself as well as the jQuery Proxigram library to access it.

The app is interesting to look at on a few levels. The package.json listing the bits and pieces I used is below. The app talks to the Instagram API, obviously uses MongoDB to cache results local to the app. It keeps that cache fresh by using Instagram’s real-time API to get updates for users. It uses passport.js for authentication (though it seems like more of the cool kids are using everyauth these days). It uses less.js for the stylesheets.

So, if you need a working example for all of those things, here you go.

Please leave feedback about things that make you itch about the code. I know a bunch of you are serious Node.js mavens, so I’m really curious what you folks think and what conventions you’re following in your projects. My biggest question at this point is how to deal with making shared components available to code in different files. For example, I made some of the authentication filters global because I split my routes up into multiple “controller-ish” files. None of the boilerplate/template apps did it better, IMHO. If you have thoughts on that one, let me know.

PS. The images on the right are getting served through Proxigram. 🙂

Here’s the dependency list from my package.json:

{
    "name": "proxigram"
  , "version": "0.1.0"
  , "private": true
  , "dependencies": {
      "express": "2.5.8"
    , "less-middleware": ">= 0.0.1"
    , "jade": ">= 0.0.1"
    , "moment": ">= 0.0.1"
    , "passport": ">= 0.1.8"
    , "passport-instagram": ">= 0.1.1"
    , "passport-http-bearer": ">= 0.1.2"
    , "mongoose": ">= 2.5.0"
    , "connect": ">= 0.0.1 < 2"
    , "connect-redis": ">= 1.0.0"
    , "connect-heroku-redis": ">= 0.1.2"
    , "airbrake" : ">=0.2.0"
    , "instagram-node-lib": ">=0.0.7"
    , "express-messages-bootstrap": "git://github.com/sujal/express-messages-bootstrap.git#bootstrap2.0"
  }
  , "engines": {
      "node": "0.6.x"
    , "npm":  "1.1.x"
  }
}

Incentivizing individual relocation vs. corporate relocation

Where We Live ran a show today on why younger people (25-34) are leaving the state. I ended up missing the show (listening to it now!), but caught a very lively discussion on Twitter.

One side conversation (you can see it on storify here) that I joined in on was about how hard it is to convince people to move to CT.

Let’s be honest. It’s hard. Harder than it should be, quite honestly, considering how nice it is to live here. I had a lot of experience with this when I was hiring people at ESPN. Even with a kick ass company, a dream job for most sports fans, and great relocation packages, it was hard to convince people to move to CT. There are a lot of reasons, and they vary by person, but they all seemed to boil down to cost and opportunity.

For people moving from a relatively low cost-of-living area, like Kansas or Vermont or Nevada, it was mostly about cost. CT looks and feels expensive when you’re browsing real estate or rents even though we’re cheap-ish for the region. For whatever reason, cost-of-living adjustments never seemed to truly capture the difference people felt.

For people moving from a big city or high cost-of-living area, like New York City or Boston or San Francisco, it was mostly about opportunity. What if they didn’t like the job here? What job opportunities would they have at a similar style company? This was exaggerated in my particular industry. There aren’t many of the kind of companies that are doing consumer Internet or mobile products that ESPN makes. If you live in NYC or Boston or SF, on the other hand, you have dozens of options plus many, many strong startup and entrepreneurial companies nearby.

There are people working on the second issue (e.g. this effort). So I asked about the cost reason, specifically:

As I mentioned, you can read the whole convo if you want, but that’s the main point.

CT just authorized $291 million in spending over 10 years to incentivize Jackson Labs to build a $1 billion facility here. Of that, $192 million is a loan that is entirely forgiven if the facility creates & retains 300 jobs in 10 years.

Now, I don’t know whether that’s a good program or not for 300 jobs, but like a lot of programs, the government seems to focus on giving money to companies rather than individuals. This isn’t bad per se, but the tradeoffs are worth talking about.

For one thing, this means that the government has to choose an industry or individual company to offer these incentives to. This doesn’t prevent existing companies from leaving, nor does it help them. That seems odd to me. But it’s also exceedingly common. Remember the brouhaha about Boeing moving it’s HQ?

Instead, I wonder if cities or states have considered incentivizing individuals to take existing jobs. For the same expenditure ($192 million over 10 years), the state could offer 5 year rent or property tax credits of $5,000 to over 7,500 families or individuals. $5,000 would cover over 100% of the median property tax for the state.

On the surface, that seems like a better use of taxpayer money. That assumes there are, of course, 7,500 jobs to fill in the state. Then again, more people moving here mean more people needing services and products. I suspect like any social network, virtual or real, there are network effects that come into play once you create some momentum.

Curious if anyone has seen studies or programs like this in the United States. I wonder how well they work, and what data we can glean from them.