Simple helper for handling error and success with two different callbacks

npm install passerror
55 downloads in the last day
393 downloads in the last week
2 641 downloads in the last month


Handle success and failure with two different callbacks. Lets you get rid of most if (err) return cb(err); constructs.


Send errors reported by fs.readFile straight to cb:

var passError = require('passerror'),
    fs = require('fs');

function getLines(fileName, cb) {
    fs.readFile(fileName, 'utf-8', passError(cb, function (contents) {
        cb(null, contents.split(/\r?\n|\n?\r/));


Licensed under a standard 3-clause BSD license -- see the LICENSE-file for details.

npm loves you