Valet: A Realtime Server for Rapid Prototyping

While developing the Robin platform at One Mighty Roar, we’ve found ourselves pushing realtime data between things like RFID kiosks, Bluetooth devices, PHP servers, and various AngularJS frontends. Along the way, we’ve built a simple but flexible server that uses and Node.js to make passing around realtime data as simple as possible.

We’ve come to think of Valet as less of a server and more of a tool – once you’ve set it up once, you can use it for many concurrent projects without any customization. In this post, we’ll go over some of the aspects of Valet and how to use it. There’s more information on the Github repo, including detailed instructions on deploying Valet on various platforms.

Installing Valet

Valet simply accepts data and re-emits it to connected clients. A client could be some Javascript running in the browser, a server, an internet-connected piece of hardware – anything that can handle WebSocket connections.

To install Valet, run:

sudo npm install -g valet

To start your shiny new Valet server on


*, run:


*Note: all of the examples on this page use the default URL http://localhost:9200. If you deploy Valet on a PaaS like Amazon EC2 or Nodejitsu, you can generally drop the port from the base URL.

Event bubbling with socket namespaces

One of our goals when building Valet was to be able to instantly use it for new projects, without writing or deploying any new server-side code. If a single instance of Valet is going to be passing data between multiple projects, it is necessary to separate the connected clients by project. can do this out-of-the-box, and it’s called “namespacing”.

Clients (frontends, devices, or even other servers) determine what namespaces they want to join by connecting to a specific URL. Multiple namespaces can be joined by calling


  multiple times (only one WebSocket connection will actually be used). For example, to join the




  namespaces, your client would have code that looks something like:

temperature = io.connect('http://localhost:9200/temperature')
humidity = io.connect('http://localhost:9200/humidity')

Valet extends’s namespaces in a useful way: if you use more complex namespaces, your events and data will “bubble up”. For example, data you send to a namespace like /buildings/123/rooms/456/temperature will be emitted on the following three namespaces:


This means that you can listen to


  to get events from temperature sensors in room 456,


  to get events from all of the temperature sensors in building 123, or


  to get events from all of the temperature sensors, everywhere.

Sending data to Valet

You can pass data to Valet by either sending a POST request to your Valet server, or by emitting a socket event called “post”. For example, to send data from your terminal using CURL:

curl -X POST -H "Content-Type: application/json" -d '{"event":"reading","data":{"temp":83.3826}}' http://localhost:9200/buildings/123/rooms/456/temperature

To send the same data using a socket is a two step process – first, you must connect to your Valet server on the root namespace. Then, emit an event called


  containing the




 , and


  you would like to emit. For example:

temperature = io.connect('http://localhost:9200');

In either case, an event called


  with data


  will be emitted on the three namespaces above.

Listening for data from Valet

Anything that can run can be a client. Simply require on your client, connect on whatever namespaces you like, and listen for events.

Here is an example client that listens for temperature readings. To demonstrate the namespace “event bubbling” behavior described above, this example listens for events on the


  namespace, even though they will be sent to the server on the





        // Connect on the "buildingTemp" namespace
        var buildingTemp = io.connect('/buildings/123/temperature');

        // "Connect" events are fired when the connection happens successfully
            console.log('connected to the "buildingTemp" namespace!');

        // Listen for the "reading" event we will be POSTing
            console.log('Got data on the "buildingTemp" namespace!');

Wrapping up

Right now, we’ve got three AngularJS apps, a PHP backend, and a Raspberry Pi all passing data through a single Valet server running on a (free) micro instance on ec2. Setting up Valet in a new project generally takes < 10 lines of code on the client-side, and no work at all on the server-side.

We wanted an always-on, realtime, easy-to-use realtime server, so we built Valet. Hopefully you’ve gotten a sense for how easy it is to start building things that can communicate in realtime.

Valet is extremely young and will continue to evolve as we find new and interesting applications for it. If you’ve got a feature you would like to see, or you come across a bug, feel free to submit an issue or pull request via Github.