Nodeku — control your Roku with Node.js

Ray Farias
3 min readOct 19, 2016

Just a few hours ago I released an NPM package called Nodeku. It will discover Roku devices on your local network and provide you with a module to interface with that device via HTTP requests. Refer to the documentation for help.

Getting Started

$ npm install nodeku

Usage

const Nodeku = require('nodeku')Nodeku()
.then(device => device.launch(12)) // launches netflix app
.catch(error => console.error(error.stack))
this sucks, change it. heh heh

Why did I build this?

I was (un)inspired by this package and how little it actually did, how it was more of a SEO boost for someone named “garciacom”, and most importantly — how the source code was no where to be found. Sketch. So I took a peak at the Roku External Control API docs and after some reading I discovered that you can send commands via HTTP requests.

Seemed like a fun side-project, I’m a web dev so this should be a piece of cake, right?

Along the way I learned about SSDP, got some practice with TDD, learned and implemented Continuous Delivery for publishing to NPM, and writing documentation.

SSDP

This was the first time I got to play with this protocol and I think it’s pretty neat. It’s a part of the Universal Plug and Plug Protocol (UPnP). Basically, devices ping a service, for example IPv4’s service resides at the IP address 239.255.255.250 port 1900, to register themselves as available devices. Once registered you can ping that same service with certain headers to get information about a particular device or about any/all devices available. Here’s an example of headers for a request looking for a Roku device:

M-SEARCH * HTTP/1.1
Host: 239.255.255.250:1900
Man: "ssdp:discover"
ST: roku:ecp

In the case of my Roku device, it responded with XML data so I had to use the xml2json package because fuck xml amirite?

xmlsux

Tests

🚀 Futuristic JavaScript test runner

I’m using a test runner called Ava. It’s nice in that it’s api is inspired by Tape, very simple and effective. It also has the ability to run tests asynchronously, I had to give it a try and so far it’s been nice.

For code coverage Nodeku is using nyc as recommended by ava’s docs. Setup was painless and getting it to work with CircleCI was as well. Here’s an image of the output:

nyc output after ava tests are completed. I’ve also read that 100% code coverage is a fool’s errand. It’s all about branches.

~ImmutableJs~

Just for kicks I threw in Immutable and I feel like it might kick me in the butt later on, maybe… we’ll see.

update 2017, Oct 6th: ImmutableJs has been removed!

Auto-publishing to NPM

Publishing made easy with CircleCI’s deployment scripts and a handy little NPM package named Publish. I set up an npm script which runs the publish binary. Publish will check what version is on NPM and what the local version is, if the local version has been bumped then it will trigger a publish onto NPM. Nifty!

What’s next?

Originally, I wanted to build an electron app to control my Roku but I figured that I need a sort of base module to interface with the device before building the electron app. So this project is a one step towards that goal.

Next, I will build a simple electron app to control my device. At the same time I will be looking at the official docs for leads on other features I could implement. The ability to search would be a good feature to have.

Enjoy and please report all issues on github.

--

--