Node Roundup: Express Form, streamline.js, long-stack-traces

2011-01-26 00:00:00 +0000 by Alex R. Young

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

Express Form

Express Form by Dan Dean is a middleware data filtering and validation library for Express. It looks
like this:

  // Route

  // Form filter and validation middleware

  // Express request-handler now receives filtered and validated data
  function(req, res){
    if (!req.form.isValid) {
      // Handle errors

    } else {
      // Or, use filtered form data from the form object:
      console.log("Username:", req.form.username);
      console.log("Password:", req.form.password);

The form method is the middleware which will add
req.form.errors and req.form.isValid. I
haven't actually used this yet but validation at the middleware layer is
very intriguing.


streamline.js released by Sage is a kind of pre-processing library for Node that makes asynchronous code look synchronous.

The example given in the documentation of asynchronous API usage is
asynchronous Node file system code (which could of course be written
with the synchronous methods anyway):

function fileLength(path, callback) {
  fs.stat(path, function(err, stat) {
    if (err) { callback(err); return; }
    if (stat.isFile()) {
      fs.readFile(path, function(err, data) {
        if (err) { callback(err); return; }
        callback(null, data.length);
    } else {
      callback(new Error(path + " is not a file"));

The streamline.js version uses the underscore symbol as a plug for
values that will be available later, so the previous example could be
written like this:

function fileLength(_, path) {
  if (fs.stat(path, _).isFile())
    return fs.readFile(path, _).length;
    throw new Error(path + " is not a file");

If you're lost in callbacks and find promises and futures unsatisfactory
you might want to try this library. It's got a lot of examples and more
features for parallelizing streamlined code.


long-stack-traces by Tom Robinson uses the V8 stack track
generate long stack traces in Node or a Chromium-based browser. It's
available through npm as long-stack-traces.

Just loading the library will make it work in Node, so this
long-stack-trace example
will produce:

Uncaught Error: readFile\
at Timer.secondTimeout (/Users/alex/example.js:6:15)\ at node.js:772:9