Gathering detailed insights and metrics for pify
Gathering detailed insights and metrics for pify
Gathering detailed insights and metrics for pify
Gathering detailed insights and metrics for pify
@types/pify
Stub TypeScript definitions entry for pify, which provides its own types definitions
@jokeyrhyme/pify-fs
the Node.js fs module, safer via graceful-fs, and more convenient via pify
@medipass/pify
Promisify a callback-style function
any-pify
A wrapper to use pify with any-promise.
npm install pify
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.7
Supply Chain
99.5
Quality
75.7
Maintenance
100
Vulnerability
100
License
JavaScript (71.47%)
TypeScript (28.53%)
Total Downloads
18,389,638,203
Last Day
14,716,591
Last Week
80,537,015
Last Month
342,585,709
Last Year
3,698,138,637
MIT License
1,504 Stars
69 Commits
67 Forks
15 Watchers
1 Branches
15 Contributors
Updated on Mar 16, 2025
Minified
Minified + Gzipped
Latest Version
6.1.0
Package Id
pify@6.1.0
Unpacked Size
13.27 kB
Size
5.04 kB
File Count
5
NPM Version
8.3.2
Node Version
14.19.3
Cumulative downloads
Total Downloads
Last Day
49.9%
14,716,591
Compared to previous day
Last Week
5.1%
80,537,015
Compared to previous week
Last Month
0.7%
342,585,709
Compared to previous month
Last Year
5.2%
3,698,138,637
Compared to previous year
5
Promisify a callback-style function
1npm install pify
1import fs from 'fs'; 2import pify from 'pify'; 3 4// Promisify a single function. 5const data = await pify(fs.readFile)('package.json', 'utf8'); 6console.log(JSON.parse(data).name); 7//=> 'pify' 8 9// Promisify all methods in a module. 10const data2 = await pify(fs).readFile('package.json', 'utf8'); 11console.log(JSON.parse(data2).name); 12//=> 'pify'
Returns a Promise
wrapped version of the supplied function or module.
Type: Function | object
Callback-style function or module whose methods you want to promisify.
Type: object
Type: boolean
Default: false
By default, the promisified function will only return the second argument from the callback, which works fine for most APIs. This option can be useful for modules like request
that return multiple arguments. Turning this on will make it return an array of all arguments from the callback, excluding the error argument, instead of just the second argument. This also applies to rejections, where it returns an array of all the callback arguments, including the error.
1import request from 'request'; 2import pify from 'pify'; 3 4const pRequest = pify(request, {multiArgs: true}); 5 6const [httpResponse, body] = await pRequest('https://sindresorhus.com');
Type: Array<string | RegExp>
Methods in a module to promisify. Remaining methods will be left untouched.
Type: Array<string | RegExp>
Default: [/.+(?:Sync|Stream)$/]
Methods in a module not to promisify. Methods with names ending with 'Sync'
are excluded by default.
Type: boolean
Default: false
If the given module is a function itself, it will be promisified. Enable this option if you want to promisify only methods of the module.
1import pify from 'pify'; 2 3function fn() { 4 return true; 5} 6 7fn.method = (data, callback) => { 8 setImmediate(() => { 9 callback(null, data); 10 }); 11}; 12 13// Promisify methods but not `fn()`. 14const promiseFn = pify(fn, {excludeMain: true}); 15 16if (promiseFn()) { 17 console.log(await promiseFn.method('hi')); 18}
Type: boolean
Default: true
Whether the callback has an error as the first argument. You'll want to set this to false
if you're dealing with an API that doesn't have an error as the first argument, like fs.exists()
, some browser APIs, Chrome Extension APIs, etc.
Type: Function
Custom promise module to use instead of the native one.
util.promisify
?util.promisify
.multiArgs
).Class methods are not bound, so when they're not called on the class itself, they don't have any context. You can either promisify the whole class or use .bind()
.
1import pify from 'pify'; 2import SomeClass from './some-class.js'; 3 4const someInstance = new SomeClass(); 5 6// ❌ `someFunction` can't access its class context. 7const someFunction = pify(someClass.someFunction); 8 9// ✅ The whole class is promisified and the `someFunction` method is called on its class. 10const someClassPromisified = pify(someClass); 11someClassPromisified.someFunction(); 12 13// ✅ `someFunction` is bound to its class before being promisified. 14const someFunction = pify(someClass.someFunction.bind(someClass));
pify
choosing the last function overload when using it with TypeScript?If you're using TypeScript and your input has function overloads, then only the last overload will be chosen and promisified.
If you need to choose a different overload, consider using a type assertion:
1function overloadedFunction(input: number, callback: (error: unknown, data: number => void): void
2function overloadedFunction(input: string, callback: (error: unknown, data: string) => void): void {
3 /* … */
4}
5
6const fn = pify(overloadedFunction as (input: number, callback: (error: unknown, data: number) => void) => void)
7// ^ ? (input: number) => Promise<number>
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 10/30 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-04-28
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More