DailyJS

Node Roundup

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

server testing node sockets

Node Roundup

Posted by Alex R. Young on .
Featured

server testing node sockets

Node Roundup

Posted by Alex R. Young on .

Welcome to the Node Roundup. Send in your apps and libraries using our
contact form or @dailyjs.

Faker.js

Faker.js (MIT License) by Marak Squires can be used in Node or a browser. It allows fake data to be
generated, for testing or rapid prototyping:

var Faker = require('./Faker');
Faker.Name.findName(); // Maximillia Hodkiewicz
Faker.Internet.email(); // Gabriella.Hermann@bartholome.co.uk

There's a demo showing the types of
data the library can generate.

I like using libraries like this with factories for quickly writing
tests (yes, I'm that lazy!)

Nodestream

Nodestream released through LearnBoost under an MIT License is a library used to connect realtime code to templates. It's built on
Jade and Socket.IO and adds a :realtime option to your Jade templates.

The simple example in the documentation demonstrates how to count the
number of people viewing your site:

var connections = 0;
var nodestream = io.listen(app).nodestream()
  .on('connect', function(){
    connections++;
    this.emit('connections', connections);
  })
  .on('disconnect', function(){
    connections--;
    this.emit('connections', connections);
  });

Template:

:realtime(repaint: 'connections', local: 'connections')
  .connections
    - if (connections > 1)
      p #{connections} people are editing right now
    - else
      p You're all alone, loser

The Socket.IO library
(server, client) supports various transports depending on the browser: WebSocket, Flash, forever iframe,
XHR long polling, and XHR multipart encoded. These are abstracted to
look like a WebSocket-like API.

Soda

Also from LearnBoost (by TJ Holowaychuk
and Adam Christian) is
Soda, which is a Selenium adapter for Node. This allows you to script browser tests, like this:

browser
  .chain
  .session()
  .open('/')
  .type('q', 'Hello World')
  .testComplete()
  .end(function(err){
    if (err) throw err;
    console.log('done');
  });

Lingo

Meanwhile, I noticed TJ has released
Lingo, which provides inflection support and other string transformations. For example:

en.pluralize('fox');
// foxes

en.singularize('foxes');
// fox

lingo.capitalize('hello there');
// Hello there

There's i18n support and a bunch of other methods.

STDIN Support for Node

While I was looking through Lingo I saw that TJ also wrote a Node patch
to add STDIN
args
.
His patch adds - and --stdin flags to the command line arguments. I
didn't realise Node couldn't do this already, which is surprising
because it's pretty important for shell scripts.