standard-as-callback is a performant JavaScript library designed to register a Node.js-style error-first callback on a Promise. It provides functionality similar to the `.nodeify()` method popularized by the Bluebird Promise library, allowing for seamless integration of promise-based asynchronous operations into environments or APIs that expect callback conventions. The current stable version is 2.1.0, with its last update occurring in 2018, indicating a maintenance status rather than active development. Its key differentiator is providing a standardized, Bluebird-inspired approach to callback conversion, particularly useful in legacy Node.js projects or when bridging modern async/await patterns with older callback-expecting interfaces. The package ships with TypeScript type definitions.
npm install standard-as-callbackVerified import paths — ran on the pinned version, not inferred.
This code demonstrates how to use `standard-as-callback` to attach a Node.js-style error-first callback to both a successfully resolving promise and a rejecting promise. It showcases basic error handling within the callback and the expected output for each scenario.
Review the source code for potential vulnerabilities or compatibility issues with newer Node.js versions. Consider alternatives like direct Promise consumption or explicit conversion utilities if more active maintenance is desired.
Always ensure your callback function properly handles the `err` argument, even if just logging it, to prevent unhandled promise rejections. Example: `(err, res) => { if (err) { console.error(err); return; } /* handle success */ }`For converting callback-based APIs to Promises, use `util.promisify` (Node.js built-in), a dedicated promisification library, or manual Promise wrapping.
Ensure the second argument to `asCallback` is a valid Node.js-style callback function with `(err, result)` signature.
Always provide a callback that handles errors, e.g., `asCallback(promise, (err, res) => { if (err) { console.error(err); return; } /* success */ })`. Also ensure the promise chain itself handles rejections if `asCallback` is not the final error handler.Run `npm install standard-as-callback` or `yarn add standard-as-callback`. Verify your import statement matches your module system (e.g., `require` for CommonJS, `import` for ESM).
No dependency data recorded yet.