{"id":11588,"library":"promisify-node","title":"Promisify Node","description":"promisify-node is a utility library designed to convert Node.js callback-style functions, methods, or entire modules into functions that return Promises. The current stable version is 0.5.0, though the project appears to be in an abandoned state with the last significant update in June 2020. Its primary differentiator is the ability to recursively wrap entire modules, automatically identifying asynchronous functions, and the option to wrap methods on objects either in-place or returning a new, non-mutated object. It uses an internal Promise implementation (or relies on a polyfill if not natively available) via `nodegit-promise` in older versions. Given its inactivity, users should be cautious about long-term support or compatibility with modern Node.js features like native ESM.","status":"abandoned","version":"0.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/nodegit/promisify-node","tags":["javascript"],"install":[{"cmd":"npm install promisify-node","lang":"bash","label":"npm"},{"cmd":"yarn add promisify-node","lang":"bash","label":"yarn"},{"cmd":"pnpm add promisify-node","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is primarily designed for CommonJS environments. Attempting to use ESM `import` syntax will likely fail in native Node.js environments without a CommonJS interop loader or a bundler.","wrong":"import { promisify } from 'promisify-node';","symbol":"promisify","correct":"const promisify = require('promisify-node');"},{"note":"To promisify an entire built-in Node.js module like 'fs', pass its name as a string directly to the `promisify` function. This returns a new object with promisified methods.","symbol":"fsModulePromisified","correct":"const fs = require('promisify-node')('fs');"},{"note":"When wrapping a single function, `promisify` takes the original function as an argument and returns a new function that returns a Promise. The original function is not modified.","symbol":"wrapFunction","correct":"const wrappedFunc = promisify(callbackBasedFunction);"}],"quickstart":{"code":"const promisify = require('promisify-node');\nconst fs = require('fs');\n\n// Wrap the entire 'fs' module. The module is cloned and then its\n// asynchronous methods are identified and promisified.\nconst promisifiedFs = promisify(fs);\n\n// Use the promisified readFile function\npromisifiedFs.readFile('/etc/passwd', 'utf8')\n  .then(contents => {\n    console.log('File contents (first 100 chars):', contents.substring(0, 100));\n  })\n  .catch(err => {\n    console.error('Error reading file:', err.message);\n  });\n\n// Example of wrapping a single function\nfunction callbackStyleAsyncFunction(value, cb) {\n  setTimeout(() => {\n    if (value) {\n      cb(null, 'Success with: ' + value);\n    } else {\n      cb(new Error('No value provided'));\n    }\n  }, 50);\n}\n\nconst promisifiedFunc = promisify(callbackStyleAsyncFunction);\n\npromisifiedFunc('Hello Promisify')\n  .then(result => console.log('Promisified function result:', result))\n  .catch(error => console.log('Promisified function error:', error.message));","lang":"javascript","description":"This quickstart demonstrates how to promisify an entire Node.js module (like 'fs') and a standalone callback-style function, then use their promise-returning interfaces."},"warnings":[{"fix":"To prevent mutation, use `const nonMutatingPromisified = promisify(originalObj, undefined, true);`","message":"By default, when promisifying an object or module, `promisify-node` mutates the original object by replacing its callback-style methods with promise-returning ones. If you need to preserve the original object, you must explicitly pass `true` as the third argument to `promisify`.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Evaluate alternatives like `util.promisify` (built into Node.js since v8.0.0) for active maintenance and better compatibility. If using this package, be aware of its unmaintained status.","message":"The package has not seen active development since June 2020. While marked 'stable' at version 0.5.0, this implies potential compatibility issues with newer Node.js versions, updated standards, or the absence of security patches for discovered vulnerabilities. It might not be compatible with native ESM modules without additional tooling.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Always test the promisified functions thoroughly. For specific functions, it might be safer to manually wrap them or use Node.js's built-in `util.promisify` on individual functions, which requires explicit identification.","message":"`promisify-node` attempts to automatically identify asynchronous functions based on heuristics (e.g., if a function's name ends with 'Sync' it's usually skipped, or if it expects a callback). This heuristic approach can sometimes lead to misidentification, either wrapping a synchronous function or failing to wrap an asynchronous one.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure the function passed to `promisify` strictly follows the Node.js error-first callback signature. For synchronous functions, no promisification is needed, as they return values directly.","cause":"Attempting to promisify a function that does not conform to the Node.js callback pattern (i.e., `(err, result) => {}` as the last argument), or passing a synchronous function.","error":"TypeError: callback is not a function"},{"fix":"Verify that the function you are trying to promisify is indeed an asynchronous, callback-style function. Debug the `promisify` call to ensure it returns a Promise. If wrapping an object, confirm the method was replaced as expected.","cause":"This error occurs when you call a promisified function but try to use `.then()` on a result that is not a Promise. This can happen if `promisify-node` failed to correctly wrap the function (e.g., due to misidentification or an unexpected function signature) and it still returns `undefined` or a non-Promise value.","error":"TypeError: Cannot read properties of undefined (reading 'then')"}],"ecosystem":"npm"}