I recently came across SocketStream, which describes itself as “A fast, modular Node.js web framework dedicated to building single-page realtime apps”.
And indeed, it took virtually no effort to get this self-updating page in a web browser:
The input comes from the serial port, I just added this code:
I’m also using Jade here, a notation which gets transformed into HTML – on the fly:
And this is Stylus, a shorthand notation which generates CSS (yep, again on the fly):
I’m slowly falling in love with all these notations – yeah, I know, very unprofessional!
Apart from installing SocketStream using “npm install -g SocketStream”, adding the SerialPort module to the dependencies, and scratching my head for a few hours to figure out how all this machinery works, that is virtually all I had to do.
Development is blindingly fast when it comes to client side editing: just save any file and the browser(s) will automatically reload. With a text editor that saves changes on focus loss, the process becomes instant: edit and switch to the browser. Boom – updated!
The trade-off here is learning to understand these libraries and tools and playing by their rules, versus having to write a lot more yourself. But from what I’ve seen so far, SocketStream with Express, CoffeeScript, Jade, Stylus, SocketIO, Node.js, SerialPort, Redis, etc. take a staggering amount of work off my shoulders – all 100% open source.
There’s a pubsub-over-WebSockets mechanism inside SocketStream. Using Redis.
Wow. Creating responsive real-time apps hasn’t been this much fun in a long time!