A tiny UDP messaging library for nodejs

In preparation for moving some of our stat collection and tracing data to UDP I’ve created Punt, an extremely small (68 SLOC) and simple library which makes UDP messaging even simpler.


The Punt protocol couldn’t be simpler either, the packet consists of a single byte for the message type, followed by the data itself. This small abstraction on top of node makes it more natural to work with UDP in JavaScript-land.


When a Punt Server is bound “message” events are emitted, retaining the original message format, meaning if you send a Buffer, you receive a Buffer, if you send an Object, it is converted to JSON and you receive an Object.

var sock = punt.bind(‘udp://');
sock.on(‘message’, function(msg){


Naturally one or more clients may connect to the server to send messages. The API is shallow, with a single .send() method:

var sock = punt.connect(‘udp://');
sock.send(‘hello world’);
sock.send(new Buffer(‘hello world’));
sock.send({ hello: ‘world’ });


Really I just wanted to try Medium for writing code articles. Hopefully others find this lib useful as well!