The JavaScript blog.


libraries node modules WebSocket command-line gulp build-tools chat

Node Roundup: nchat, hulken, cult

Posted on .


nchat (GitHub: irrationalistic/nchat, npm: nchat) by Chris Rolfs is a terminal-based chat application that uses WebSocket, which means it's easier to use on networks where IRC might be blocked.

Notifications are supported on Mac OS X, and the client can run as the server so you only need to install nchat itself. It supports a few IRC-style commands, like /users, and you can deploy it to hosting providers like Heroku.


Hulken (GitHub: hulken, License: MIT, npm: hulken) by Johan Hellgren is a stress testing tool for HTTP services. It can make GET and POST requests, and can be configured to send dynamic payloads.

You can use hulken as a command-line tool, or a Node module. The documentation includes all of the supported options, and you'll need to write an options.json file to use it on the command-line.


Cult (GitHub: typicode/cult, License: MIT, npm: cult) is a tool that monitors changes to a gulpfile and then reloads Gulp. You can run it on the command-line, and it uses the chalk library for pretty output. The readme has an example for supporting gulpfiles that are split across multiple files.


libraries ui WebSocket angularjs

Ment.io, Coffea, Marilyn

Posted on .



Ment.io (GitHub: jeff-collins / ment.io, License: MIT) is a UI component for handling Twitter/GitHub style @ mentions. It has no dependency on jQuery, and it's designed for use with AngularJS.

An ngModel is used for data, and the mentio-menu element is used to define the menu that appears during typing. You can use the mentio on a suitable input or content editable element to indicate where Mentio should appear.


Coffea (GitHub: caffeinery / coffea, License: BSD, coffea) by Daniel Bugl is an event-based IRC client library. It supports SSL, and the API seems very friendly to Node developers:

var client = require('coffea')({  
  host: 'irc.freenode.org'

client.on('motd', function(motd) {  
  client.join(['#foo', '#bar', '#baz']);

client.on('message', function(event) {  
  console.log('[' + event.channel.getName() + '] ' + event.user.getNick() + ': ' + event.message);


Marilyn (GitHub: alanjames1987 / marilyn, License: MIT) by Alan James Pub/Sub model API with a similar API to Mongoose. It's event-based, so you can hook into events that are triggered before and after CRUD operations.

You can create models like this:

var MyModel = Marilyn.model('someModelName');  

The before and after events can be defined in the initialisation callback that gets passed to the model method.

Marilyn.model('someModelName', function() {  
  this.before('create', function(data, next) {
    // this is useful for validating data before a CRUD method runs
    console.log('I ran before');

  this.after('create', function(data, next) {
    // this is useful for altering data before it's returned to the controller
    console.log('I ran after');


node modules WebSocket internationalisation

Node Roundup: SocketCluster, i18n-generator, generator-gulp-angular

Posted on .


SocketCluster (GitHub: TopCloud / socketcluster, npm: socketcluster) is a WebSocket server designed with clustering in mind. The developers have tested for memory leaks and included benchmarks. It handles client reconnection if a server crashes, and has a clustered memory store for temporary session data.

SocketCluster lets you store session data using the socket.session object. This object gives you access to a cluster of in-memory stores called nData. You can effectively invoke any of the methods documented here to store and retrieve session data: https://github.com/topcloud/ndata

Basic usage looks like this:

var SocketCluster = require('socketcluster').SocketCluster;

var socketCluster = new SocketCluster({  
  workers: [9100, 9101, 9102],
  stores: [9001, 9002, 9003],
  balancerCount: 1,
  port: 8000,
  appName: 'myapp',
  workerController: 'worker.js',
  rebootWorkerOnError: false,
  addressSocketLimit: 50

The project is built with iocluster and loadbalancer, by the same authors.


i18n-generator (GitHub: huei90 / i18n-generator, License: MIT, npm: i18n-generator) by Huei Tan is a library for converting i18n text files into JSON.

For example, given this input:

i18n=> | en | zh_TW | de | my  
you | you | 你 | Du | kamu  
I | I | 我 | ich | Saya  
love | love | 喜歡 | liebe | cinta  
eat | eat | 吃 | essen | makan  
ilovegithub | i love github | 我愛 Github | ich liebe Github | Saya cinta pada Github  

It would generate this:

{"you":"you","I":"I","love":"love","eat":"eat","ilovegithub":"i love github"}

for each language. It comes with tests and browser support.


I find it difficult to work on MVVM projects without some sort of build system so I can at least structure the project with CommonJS or AMD. generator-gulp-angular gives you a Yeoman generator that uses Gulp, Bowser, and AngularJS.

This generator aims to takes the best from others generators like generator-angular, ngTailor and generator-gulp-webapp to offers the best workflow to start an application with AngularJS powered by Gulp!

generator-gulp-angular scaffolds out an AngularJS application with a full featured gulpfile.js which offers all the tasks for modern web development.

It seems like a good way to get started with Gulp and AngularJS, which can actually be a little bit daunting.


games node WebSocket

Tetris with WebSockets

Posted on .

Tetris with WebSockets.

A few weeks ago I ran an introductory Node workshop at Makers Academy:

Makers Academy is a highly selective, 12 week full-time programme that teaches web development in London. We accept only the top applicants onto the course for a rigorous programme that culminates with the graduation day when we introduce them to London's top technology companies looking to hire entry-level developers.

The workshop had a 50 minute talk where I introduced Node, then we set the students a challenge: improve our Tetris game. The challenges started at basic UI improvements and ended at intermediate Node web development.

To make the game, I created a small Tetris game engine -- using test-driven development, naturally. The idea behind the game and workshop was to get people thinking about what Node is good at, but we also had an ulterior motive: recruitment. We were struggling to hire a web junior web developer with Node skills, so Makers Academy provided us with a unique opportunity to talk to some enthusiastic new developers.

I've written a more detailed post about the workshop on Medium: An introductory Node workshop at Makers Academy. I enjoyed writing the game engine as a Node module, and it made me want to try making a bigger WebSocket powered game... (when my book is finished!)


frameworks graphics games modules WebSocket webrtc

voxel.js, holla, Blitz, OneJS 2.0

Posted on .



When I was at BathCamp this week, Andrew Nesbitt mentioned voxel.js -- a collection of projects for building browser-based 3D games. The core components were written by Max Ogden and James Halliday, take a look at voxel-engine (GitHub: maxogden / voxel-engine, License: BSD, npm: voxel-engine) if you want to see some code examples.

There are lots of demos on the voxel.js site, at the moment most of them support simple world traversal and the removal of blocks just like Minecraft. The project also has add-ons which includes voxel-creature for adding NPCs and player-physics. A huge amount of effort has already gone into the project, and it was apparently inspired by the awesome 0 FPS blog posts about voxels.


holla (GitHub: wearefractal / holla, License: MIT, npm: holla) from Fractal is a module for WebRTC signalling. The author calls it "WebRTC sugar" -- compared to the underlying API the library's use of methods like .pipe make it a lot easier to get the hang of.

It has some helpers for creating audio and video streams, and there's a demo up at holla.jit.su that accesses your webcam and microphone.


Blitz (GitHub: Blitz, License: Modified MIT) by Eli Snow can help safely extend objects, overload functions based on types and arguments, and provides some native type recognition across global contexts:

Unlike other frameworks that have one generic wrapper for every object, Blitz creates unique wrappers for every prototype. So, for example, instead of having one method replace that works only with Arrays we can have a replace method for Arrays another for HTMLElements and/or any other object type.

Some of the functionality is accessible through a chainable API, so you can do things like this:

// [35, 16]
blitz([35, 16, 21, 9]).length(2).value;  

Function overloading works using blitz.overload, which accepts an object that lists types alongside target functions.

OneJS 2.0

Azer Koculu has updated OneJS to version 2.0. OneJS converts CommonJS modules to standalone, browser-compatible files. It now supports splitting bundles into multiple files, and loading them asynchronously. It also has a more flexible build system: you can use it from the command-line, package.json, or from within a Node script.