Registry / http-networking / promisify-node

promisify-node

JSON →
library0.5.0jsnpmunverified

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.

npm install promisify-node
INSTALL
IMPORT
SIG · PROMISIFY-NODE
P
promisify-node
http-networkingjavascriptv0.5.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

promisify
const promisify = require('promisify-node');
import { promisify } from 'promisify-node';
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.
fsModulePromisified
const fs = require('promisify-node')('fs');
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.
wrapFunction
const wrappedFunc = promisify(callbackBasedFunction);
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.

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.

const promisify = require('promisify-node'); const fs = require('fs'); // Wrap the entire 'fs' module. The module is cloned and then its // asynchronous methods are identified and promisified. const promisifiedFs = promisify(fs); // Use the promisified readFile function promisifiedFs.readFile('/etc/passwd', 'utf8') .then(contents => { console.log('File contents (first 100 chars):', contents.substring(0, 100)); }) .catch(err => { console.error('Error reading file:', err.message); }); // Example of wrapping a single function function callbackStyleAsyncFunction(value, cb) { setTimeout(() => { if (value) { cb(null, 'Success with: ' + value); } else { cb(new Error('No value provided')); } }, 50); } const promisifiedFunc = promisify(callbackStyleAsyncFunction); promisifiedFunc('Hello Promisify') .then(result => console.log('Promisified function result:', result)) .catch(error => console.log('Promisified function error:', error.message));
Debug
Known issues
gotchaBy 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`.
fix
To prevent mutation, use `const nonMutatingPromisified = promisify(originalObj, undefined, true);`
affects: >=0.1.0
breakingThe 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.
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.
affects: >=0.5.0
gotcha`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.
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.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: callback is not a function
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.
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.
TypeError: Cannot read properties of undefined (reading 'then')
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.
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.
Upgrade
Version history
0.5.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
promisify-node — npm install promisify-node · libregistry