New Open-Source Launch: NPR One JavaScript SDK

Nara Kasbergen
Technology at NPR
Published in
4 min readAug 10, 2016

--

About a month ago, I wrote about how my team was putting the finishing touches on our open-source JavaScript SDK for NPR One. Well, I'm excited to announce that it's finally here!

I already mentioned a lot of our motivations in my post about the proxy, so I’ll try not to be too repetitive here. Essentially, we’ve tried to package together common tasks to provide a more user-friendly API for developers who are coding an NPR One app in JavaScript. In particular, our partner-developers have repeatedly cited figuring out when to send ratings and how to get the next recommendation as a pain point; this SDK significantly simplifies such steps. Even for those developing on other platforms, JavaScript is a universal enough language we hope that this SDK will be a great companion to our documentation.

A story on the NPR One webapp. Screenshot courtesy of NPR Design.

As I mentioned when we open-sourced the proxy, we believe strongly in dog-fooding our own work, so this SDK is currently powering all communication between our APIs and the NPR One webapp. We hope this gives you confidence that this package is tried and tested and production-ready! If you are one of our partner-developers and your platform supports HTML5 and/or JavaScript, you can incorporate this directly into your NPR One app. In other words, you can spend less time writing boilerplate code and more time creating a simple and delightful UI that fits our design guidelines.

Of course, we realize that there are other developers and hobbyists who might be interested in NPR's open-source work, regardless of whether your end-goal is to build a full-fledged NPR One app or something entirely different. This SDK should be flexible enough to allow you to mash up the functionality in interesting ways and build something new and creative, even if that's not what it was expressly designed for.

What's particularly exciting is that this SDK is set up as a Universal JavaScript Module, which means that it will work out-of-the-box in a client-side browser application just as well as in a server-side node.js app. So, not only can you use this as part of an HTML5 webapp, but you could also integrate it with an Arduino or a Raspberry Pi using the popular node.js-based Johnny-Five robotics & IoT platform (as just one of many examples).

Have I convinced you to give it a try? Here’s how to get started:

Assuming a recent version of node.js (v0.12.x or newer) and npm are installed globally on your system, you can install the SDK with:

npm install npr-one-sdk --save

…which will add the latest stable version to your existing node.js project.

For those using node.js with Bower as your frontend package manager, we’ve also made this SDK available there. Run:

bower install npr-one-sdk --save

…to add the latest stable version of this SDK to your existing Bower project.

Please be aware that we may cease to support Bower in the future. Unless you plan to integrate this SDK into a project that is already using Bower, we highly recommend using npm.

Once you’ve successfully added the SDK to your project, the Setup section in our README on GitHub will guide you through the rest of the steps to get started. We’ve also generated a full documentation site from our code’s docblocks using ESDoc, which will give you a full list of available functions, their input parameters, and output formats.

Here at NPR, we’ve embraced the next generation of web technologies and are coding all of our new JS projects using ECMAScript 6 (ES6), the latest stable version of the standard. However, our output files are transpiled using Babel, so all of the code still runs in older browsers, and you can safely code your own functionality in ES5 and still use our SDK.

That said, if using ES6 is an option (with or without a transpiler like Babel), that’s what we recommend. While we’re doing our best to provide code samples in both ES5 and ES6, it’s highly likely going forward that we’ll be providing the majority of our sample code in ES6 rather than ES5. We’ll also probably be able to respond to issues faster if you’re working with and can provide examples in ES6.

On that note, we’re excited to hear your feedback and encourage you to submit issues and pull requests or send us an e-mail. If you do submit a pull request, we’re using Travis CI to verify that all of our unit tests still pass and Coveralls to ensure that our unit test coverage doesn’t drop below 100%. This is our team’s first time using Travis and Coveralls (and only the second package we’ve open-sourced), so there might be some growing pains, but we’re excited to explore this new and more open workflow.

With that, get hacking! And if you build something cool, please drop us a line and tell us about it. 😄

--

--

🇳🇱🇮🇩🇨🇳 immigrant married to a 🇰🇷🇺🇸. She/her. INFP. Eng manager looking for a new adventure. Mental health advocate. Foodie. Gamer. ❤️: 💅🏻🍷 & 🐧