Binary encoding deprecation in Node.js

Recently I had to implement an endpoint for an archaic API in Node.js, which required some binary manipulation.

Giving a quick peak at documentation, you will see that binary encoding should be avoided at all costs and is already deprecated, instead you should rely on buffers.

Here goes a really basic and quick example doing the same thing using encoding and then using buffers.

What you should NOT be doing:

stream.write(utils.pack('N', + 4) +,
 'binary', payload.callback);

Instead you should be doing:

var myb = new Buffer( + 4);
myb.writeUInt32BE(( + 4), 0);
myb.write(, 4);
stream.write(myb, payload.callback);

Realize that when you use a buffer in the write method, encoding does not fallback to utf8 by default.


SSH connection’s channel limit and Node.js

Recently while rebuilding Outkept, I learned something interesting. I knew there was a channel limit for each SSH connection, what I didn’t know was that the default limit was so low (usually 8 channels per connection by default in the majority of ssh daemons).

In Outkept each sensor uses a channel, if I exclusively used one channel per sensor that meant that only 8 sensors per server was allowed.

This meant that I needed to implement a queue based pool of some sort, in order to “multiplex” the available channels. Something like the gist below, just pass it a SSH2 module connection object and use the send method.

This code does not feature stream error treatment, so complement it or only use it when missing something isn’t important.

In this use case, each sensor interval is user defined, if someone defined a few sensors with intervals in the millisecond range the queue is going to quickly fill forever. I monitor this alerting the user in the dashboard for a “queued up” scenario, in this situation there is only two solutions: increase the intervals or increase the channels limit.

Rebuilding Outkept

Outkept DashboardLast November I did a talk at Codebits about a private project that ended to be Outkept, it was basically a project that was build for a  specific use case and then I generalized it.

At the time I developed it in Java, but after the talk I decided to rebuild it for more generalist use cases and start everything entirely from scratch in node.js.

Outkept allows you to control and monitor a large server cluster, without needing to manually specify which and what servers to monitor/control. Instead you just define which subnets you want to control and then, using SSH, Outkept‘s crawlers will look for servers and what do they support.

Rebuilding it in node.js was awesome, allowing me to tackle my node.js skills and dig more into node’s scene while using a lot ‘earlier adopter’ tech.

Right now Outkept v2 supports everything the old version supported and even more, things are quicker and more fluid. New dashboard connects using shoe (sockjs) and the new system relies entirely in multiple node.js processes.

I will talk more about this project later, but right now I would love some feedback. The codebase is big and mostly uncommented, in the next posts will fix this and talk a bit about it.

If you want to give it a try just follow these instructions. If you need help you can reach me at