Writing My First Node Package

Brady Whitten
2 min readMar 8, 2015

--

I finally got around to (properly) learning how to write and publish a Node.js package.

npmjs.com/packages/opensecrets-client

I chose to write one around the Opensecrets.org API. I have plans to turn this Node package into a Meteor smart-package, making it reactive and usable from within Meteor, ultimately allowing me to write a basic app around the data. Funnily enough, I searched NPM for a package which existed already for this and found nothing. Why? I searched for open secrets instead of opensecrets. The former returns a massive listing of results around opening things… naturally. The latter finds 3 pre-existing libraries for the same thing I ended up doing. Had I actually searched for opensecrets initially I may not have learned how to do any of these things at all!

I ended up making this library short and succinct. It has a simple API, only one truly public method, and utilizes other packages everywhere possible. In that regard, I ended up utilizing restler for the HTTP client aspect, qs to generate the correct query string from option objects, and dotenv to enable the use of environment variables (for better security and portability of a users API key).

Testing wise… well… I didn’t really know what I was doing here. After some searching around, and at the (blog) advice of some well regarded Node community members, I ended up choosing the great mocha library. To me it resembles a kind of BDD methodology, though you can do essentially any type of testing within it.

Anyway, it was a fun learning exercise building this thing, even if others had already done it a different way. But that’s how the Javascript world works, right?

Oh, and go Duke (we’ll see how history plays out with this one).

</firstPost>

--

--