The JavaScript blog.


apps realtime servers node

A Server for Realtime Apps: deepstream.io

Posted on .


Wolfram Hempel sent in an open source server called deepstream.io (GitHub: hoxton-one/deepstream.io, License: MIT, npm: deepstream.io). Deepstream is a Node server that allows clients to sync data, whether they're browsers or mobile applications. It has a caching layer, and supports event-based messaging and RPC.

If you install deepstream.io with npm, you can create a simple server like this:

var DeepstreamServer = require( 'deepstream.io' );  
var server = new DeepstreamServer();

server.set('host', 'localhost');  
server.set('port', 6020);


Then in the browser you can connect with var ds = deepstream('localhost:6020').login(). The ds object can be used to fetch and set data. The tutorial shows how to do this with a simple HTML form:

var record = ds.record.getRecord('someUser');  
var input = document.querySelector('input');

input.onkeyup = function() {  
  record.set('firstname', input.value ;

record.subscribe('firstname', function(value) {  
  input.value = value;

The RPC calls allow functions to be bound to function names. One nice property of RPC in deepstream is if multiple clients are able to provide the same RPC, it will distribute requests evently between them.

The project is still new, but there are a good amount of tutorials already, including React and Angular examples.


node realtime modules npm

Node Roundup: Money and npm, Isaac Schlueter Interview, KOAN

Posted on .

Nebulous Profit Meditations

Isaac Schlueter wrote a long article on the npm blog about how npm Inc. will make money. It has some hints about the future of advertising on npm:

In my opinion, a good example of advertising done very well is the hosting page on WordPress.org. The services offered are beneficial to WordPress users, and are offered in such a way as to avoid distracting from the core product. The focused curation increases the value, and provides a strong incentive for the advertised products to maintain their quality or risk losing their position. We will be pursuing similarly focused and curated advertising partnerships on the npm website, in ways that benefit our users as well as our technology partners.

And GitHub's influence:

When I describe our plans to people, they often nod and say, "Oh, the GitHub model, ok." I'm sure that "public for free, private costs money" isn't new with GitHub. However, pursuing that kind of model, while at the same time acknowledging that coding is a social activity, really was a master stroke in the history of software development. I'm very thankful that they've helped pave the way for people to recognize this pattern.

Meet the Face Behind npm

The Modulus hosting company blog has an interview with Isaac, with some history prior to Node and npm:

At Yahoo!, I grew increasingly frustrated that I had to switch back and forth between PHP and JavaScript, and Google had just open sourced their V8 engine, so I started trying to seriously get into doing JavaScript on the server. I got involved with the K7 project, and started studying web servers in more detail. There was also SpiderApe, and v8cgi, and a bunch of other projects. Narwhal caught my eye, and I spent a bunch of time messing with that.

I seem to remember making IRC bots with Rhino and Java sockets, then Node came along and changed everything!


KOAN (GitHub: soygul / koan) by Teoman Soygul is a full stack boilerplate that uses Koa, AngularJS, Node, and MongoDB. Unlike other similar projects, this one has WebSocket features baked in.

A KOAN app uses JSON-RPC for syncing data with the server, and the readme has details on how to deploy this to Heroku (using labs:enable websockets).


css node realtime modules

Node Roundup: Browserify, NowJS, Vogue

Posted on .


Browserify (GitHub: substack / node-browserify) by James
Halliday makes CommonJS packages work in browsers by bundling up modules
into a monolithic file. I know we've had a lot of script loaders on
DailyJS, and detailed discussions about monolithic files vs. loading
scripts on demand, but I assume James has structured Browserify this way
to make the require syntax easy to support.

The package includes Connect middleware:

var connect = require('connect');
var server = connect.createServer();
server.use(require('browserify')(__dirname + '/js'));


The dependency support is interesting as well:

If the npm modules have dependencies, those dependencies will get bundled along recursively!

It's also possible to run modules through minifiers, using post-filters.

I think this must be the most convenient way to share code between Node
and browsers that I've seen so far.

I also seem to remember writing about
Nodules which is similar to this project, and brequire.


NowJS (GitHub: Flotype / now) aims to make real-time applications
easier to develop by synchronising functions and variables in a
namespace between clients and a server.

It can be set up with an Express app like this:

var app = express.createServer();
var everyone = require("now").initialize(app);

The authors have already written a NowJS Coding Patterns and Best
guide, which explains how to
filter messages at the client-side (for creating rooms in a chat
application), and tips for keeping things efficient.


Vogue (GitHub: andrewdavey / vogue,
License) by Andrew Davey automatically reloads stylesheets whenever they're
saved. It uses Socket.IO so it feels pretty
responsive. It's a great idea for use during development, and I imagine
it would blow your design team's collective minds.


server programming node realtime

Juggernaut Tutorial

Posted on .

This article is by [Alex MacCaw](http://www.eribium.org/). He's a JavaScript and Ruby developer and his blog is [Lead Thinking](http://leadthinking.com/). Follow him on Twitter here: [@maccman](https://twitter.com/maccman).

Juggernaut gives you a realtime connection between your servers and client browsers. This lets you do
awesome things like multiplayer gaming, chat, group collaboration and
more. What's more, Juggernaut is built on top of
node.js so you can take advantage of its incredible speed and scalability.

Example code is worth a thousand words, so here's a simple group chat
implementation using Juggernaut:

   var jug = new Juggernaut;
   jug.subscribe("/chats", function(data){
     $("#chats").append($("<li />").text(data));

That's it, the browser will set up a streaming connection to
Juggernaut's node server. Any messages pushed to the channel "/chats"
will be sent to the client. For example, we can push data from a Ruby

require "juggernaut"
Juggernaut.publish("/chats", "Hello World!");

That's all the code you need - all clients connected will see the

Juggernaut's features include:

  • node.js server
  • Ruby client
  • Supports the following protocols:
    • WebSocket
    • Comet
    • Adobe Flash Socket
  • Reconnection support
  • Massive horizontal scaling


So you want to try it out? We need to install some dependencies first:

# Install node.js

Right, now we need to start "Redis":http://code.google.com/p/redis/ ("install":http://code.google.com/p/redis/wiki/QuickStart it if you don't have it already). Juggernaut uses Redis for PUBSUB:

./redis-server redis.conf

Download Juggernaut, and start the Juggernaut server:

git clone git://github.com/maccman/juggernaut.git
cd juggernaut
node server.js

That's it! Open http://localhost:8080 and you'll see Juggernaut in


Now we've got our client running, let's publish to it. We need to
install the Ruby gem to do so (don't forget the --pre option!):

sudo gem install juggernaut --pre

And now in irb:

require "juggernaut"
Juggernaut.publish("channel1", "Yo yo yo")

You can also publish to multiple channels:

Juggernaut.publish(["channel1", "chan2"], "yo yo, my good fellow")

And send objects:

Juggernaut.publish("channel1", {:where => "is my yo yo?"})


So, that's a brief introduction to Juggernaut. You can check out more
use cases in the README. Now go
and build something awesome!