// instead of:
if (util.isError(err) && (err.message !== ''))
// use just:
if (err)
// instead of:
next(err)
// use:
return next(err) // ditto for other callbacks
// either throw or call back, but never both:
callback(err);
throw err;
// instead of anonymous functions:
function(cb) {}
// always name functions for better traceability:
function loadConfig(cb) {}
// instead of:
init(function startServer(db) {
// always send (err) as the first argument to any callback:
init(function startServer(err, db) {
In general, parallel-ize wherever possible.
// this is the business logic you care about
vasync.parallel([ foo, bar, biz, baz ], onComplete);
// forces another good convention: no anonymous functions!
function foo(done) { }
function bar(done) { }
function biz(done) { }
function baz(done) { }
function onComplete(err, results) { }
http.globalAgent.maxSockets = Infinity;