{"id":16224,"library":"standard-as-callback","title":"Standard asCallback","description":"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.","status":"maintenance","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/luin/asCallback","tags":["javascript","ascallback","nodeify","promise","bluebird","typescript"],"install":[{"cmd":"npm install standard-as-callback","lang":"bash","label":"npm"},{"cmd":"yarn add standard-as-callback","lang":"bash","label":"yarn"},{"cmd":"pnpm add standard-as-callback","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library primarily offers a default export for the asCallback function, common for single-function CommonJS modules.","wrong":"import { asCallback } from 'standard-as-callback';","symbol":"asCallback","correct":"import asCallback from 'standard-as-callback';"},{"note":"This is the standard CommonJS `require` pattern for modules with a default export, as shown in the original documentation.","wrong":"const { asCallback } = require('standard-as-callback');","symbol":"asCallback","correct":"const asCallback = require('standard-as-callback');"},{"note":"When using TypeScript, you can import the type definition for the asCallback function signature to ensure type safety, assuming the package exports this type directly.","symbol":"AsCallbackFunction","correct":"import type { AsCallbackFunction } from 'standard-as-callback';"}],"quickstart":{"code":"import asCallback from 'standard-as-callback';\n\n// Example 1: A simple resolving promise\nconst resolvingPromise = new Promise<string>((resolve) => {\n  setTimeout(() => {\n    resolve('Operation successful!');\n  }, 500);\n});\n\nasCallback(resolvingPromise, (err, res) => {\n  if (err) {\n    console.error('Callback error (resolvingPromise):', err);\n    return;\n  }\n  console.log('Callback result (resolvingPromise):', res); // null, 'Operation successful!'\n});\n\n// Example 2: A promise that rejects\nconst rejectingPromise = new Promise<string>((_resolve, reject) => {\n  setTimeout(() => {\n    reject(new Error('Something went wrong!'));\n  }, 1000);\n});\n\nasCallback(rejectingPromise, (err, res) => {\n  if (err) {\n    console.error('Callback error (rejectingPromise):', (err as Error).message); // 'Something went wrong!'\n    return;\n  }\n  console.log('Callback result (rejectingPromise):', res);\n});","lang":"typescript","description":"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."},"warnings":[{"fix":"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.","message":"The package has not seen active development since 2018 (version 2.1.0). While stable, consider its long-term maintenance status when adopting for new projects or relying on modern JavaScript features.","severity":"gotcha","affected_versions":">=2.1.0"},{"fix":"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 */ }`","message":"If the provided Promise rejects and no error-handling logic is included in the callback, the rejection might still become an unhandled promise rejection if not caught elsewhere in the Promise chain.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For converting callback-based APIs to Promises, use `util.promisify` (Node.js built-in), a dedicated promisification library, or manual Promise wrapping.","message":"`standard-as-callback` is designed to convert Promises into callback-style APIs. It is not intended for converting callback-based APIs into Promises (a process often called 'promisification').","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2.1.0':62 '2018':69 'activ':76 'allow':39 'api':52 'approach':88 'ascallback':2,118 'async/await':102 'asynchron':47 'base':46 'bluebird':36,86,121 'bluebird-inspir':85 'bridg':100 'callback':6,21,55,90,107 'callback-expect':106 'convent':56 'convers':91 'current':58 'definit':116 'design':12 'develop':77 'differenti':80 'environ':50 'error':19 'error-first':18 'expect':54,108 'first':20 'function':27 'indic':70 'inspir':87 'integr':42 'interfac':109 'javascript':10,117 'key':79 'last':65 'legaci':95 'librari':11,38 'mainten':72 'method':32 'modern':101 'node.js':16,96 'nodeifi':31,119 'occur':67 'older':105 'oper':48 'packag':111 'particular':92 'pattern':103 'perform':9 'popular':33 'project':97 'promis':24,37,45,120 'promise-bas':44 'provid':26,82 'rather':74 'regist':14 'seamless':41 'ship':112 'similar':28 'stabl':59 'standard':1,4,84 'standard-as-callback':3 'status':73 'style':17 'type':115 'typescript':114,122 'updat':66 'use':93 'version':60","created_at":"2026-04-21T19:18:54.491448+00:00","updated_at":"2026-04-21T19:18:54.491448+00:00","problems":[{"fix":"Ensure the second argument to `asCallback` is a valid Node.js-style callback function with `(err, result)` signature.","cause":"The second argument passed to `asCallback` was not a function.","error":"TypeError: callback must be a function"},{"fix":"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.","cause":"A Promise passed to `asCallback` rejected, but the provided callback did not handle the `err` argument, or no callback was provided, leading to the rejection not being consumed.","error":"UnhandledPromiseRejectionWarning: Unhandled promise rejection."},{"fix":"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).","cause":"The package is not installed, or there's a misconfiguration in your module resolution (e.g., incorrect CJS/ESM import in the wrong environment).","error":"Cannot find module 'standard-as-callback'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/luin/asCallback","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/standard-as-callback","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-20","install_tag":null}}