Node Roundup: LazyBoy, node-fibers, NsSocket

10 Aug 2011 | By Alex Young | Tags node modules fibers network

You can send your node modules and articles in for review through our contact form or @dailyjs.

LazyBoy

LazyBoy (GitHub: garrensmith / LazyBoy, License: MIT, npm: LazyBoy) by Garren Smith is a CouchDB object mapper:

var Model = require('LazyBoy');

Model.define('User', {
  name: String
  surname: {type: String, default: 'Rambo'}
});

var user = Model.create('User', { name: 'John', surname: 'Rambo' });

user.save(function(err, saved_user) {
});

var User = Model('User');
User.find('some id', function(err, user) {
});

The API reminds me of Mongoose, where models are registered then fetched back later. The author has written tests, and intends to add some useful features like validation later.

node-fibers 0.5

node-fibers (License: MIT, npm: node-fibers) by Marcel Laverdet has just been updated to version 0.5:

I recently pushed out version 0.5 which most notably adds a nifty implementation of futures which supports synchronous wait’ing in lieu of callback chains in NodeJS.

Fibers are a convenient way of wrapping code that blocks in something like a thread — “coroutines” is the more accurate term. To get a good sense of what fibers are and how they can help with certain classes of problems, Adding fibers to v8: efficiency + clarity in SSJS covers the subject very well.

NsSocket

NsSocket (npm: nssocket) from Nodejitsu wraps network sockets with events and automatic buffering to help simplify string-based network communication.

The default namespace delimiter is :::

nsSocket.on('data::some::evented', function(datas) {
  console.log(datas);
}

The authors have written up a full example that demonstrates the basic functionality:

var net = require('net'),
    nssocket = require('nssocket');

// Config object
var config = {
  delimiter : '::' // default (recommended)
  type : 'tcp' // default (tcp, tls)
  msgLength : 3 // default (can be any length, technically even 1)
};

// socket gets wrapped
var socket = new net.Socket({ type: 'tcp4'}),
    nsSocket = nssocket.NsSocket(socket, config);

nsSocket.connect(80, '127.0.0.1', function onConnect() {
  // pass in an array
  nsSocket.send(['hello', 'world', 'derp']);
  console.dir('success!');  
});

blog comments powered by Disqus