Registry / devops / drainer

drainer

JSON →
library0.2.1jsnpmunverified

Minimal async task queue that runs an array of functions in series, passing results between them. Version 0.2.1 is the latest and only release. Simple alternative to async.waterfall or p-series, with no dependencies. Provides two modes: direct execution with shared default arguments, and chaining where each function receives the previous function's result. Error handling stops the chain and passes the error to the final callback. Ideal for small Node.js scripts or legacy codebases that need a lightweight serial execution pattern.

npm install drainer
INSTALL
IMPORT
SIG · DRAINER
D
drainer
devopsjavascriptv0.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import drainer from 'drainer'
const drainer = require('drainer')
Package does not ship ESM or TypeScript types; CJS require is the only supported usage.
drainer
const drainer = require('drainer')
import { drainer } from 'drainer'
CommonJS default export, not named export.
drainer (as function name)
const drain = require('drainer')
const { default: drain } = require('drainer')
Simple require yields the function directly; no destructuring needed.

Shows two usage patterns: chaining results between functions, and passing default arguments to all functions.

const drainer = require('drainer'); // Queue functions that execute in series, passing results. drainer([ function (next) { // first function: start with no input next(null, 1); }, function (prevResult, next) { // prevResult === 1 from previous step next(null, prevResult + 1); }, function (prevResult, next) { // prevResult === 2 next(null, prevResult + 1); } ], function (err, finalValue) { if (err) { console.error('Error:', err); } else { console.log(finalValue); // 3 } }); // Or with default arguments shared across all functions: const drain = drainer([ function (arg1, arg2, next) { next(null, arg1 + arg2); }, function (arg1, arg2, next) { next(null, arg1 * arg2); } ]); drain(2, 3, function (err, result) { console.log(result); // 6 (from the last function) });
Debug
Known issues
gotchaIf you call next() without arguments, it passes undefined as the error, which will stop the chain and trigger the final callback with an undefined error.
fix
Always call next(null, result) to pass results, or next(err) to signal error.
affects: >=0.0.0
deprecatedPackage has not been updated since 2013. No ESM support, no TypeScript types, no async/await compatibility.
fix
Consider modern alternatives like p-series, async/waterfall, or for-await-of loops.
affects: 0.2.1
gotchaDefault arguments mode: when using drain = drainer(functions) then calling drain(...args, callback), arguments are shared as references, so mutations affect later functions.
fix
Clone or copy arguments if you need to avoid mutation.
affects: >=0.0.0
Errors
Common errors & fixes
drainer is not a function
Incorrect import: trying to use named import from ESM or destructuring from CJS.
fix
Use const drainer = require('drainer');
TypeError: next is not a function
Function signature expects a callback 'next', but you defined a function without parameters.
fix
Ensure each function in the array accepts at least one argument (the callback) or the correct number of default args + next.
Unhandled 'error' event
Error passed to next() but final callback not provided or does not handle error.
fix
Always attach a final callback with (err, result) => { ... } and check err.
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
drainer — npm install drainer · libregistry