npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

promisfy

v1.2.0

Published

transform a node-style asynchronous function to promise-style function, very handy for async/await

Readme

promisfy

description

this package is used for transform a node-style asynchronous function to a promise-style function. It's very handy if you are using async/await. After v1.1.0, you can also use it for a event callback.

a node-style asynchronous function should be like this:

function asycFunction(arg1, arg2, callback) {
    // do something
}

// callback should be like this
function callback(err, result) {
    // do something
}

The first argument err represents whether the asynchronous call is failed(null while it's successful), and the second argument is the result of this call.

install

npm install --save promisfy

usage

very simple to use:

const fs = require('fs');
const http = require('http');
const {promisfy, waitFor} = require('promisfy');

// using promisfy
// if you are using some some callbacks without error as its first argument,
// try promisfyNoError()
const readFile = promisfy(fs.readFile);

async function main() {
    let content = await readFile('myfile.txt', {encoding:'utf8'});

    return content;
}

main().then(function(content) {
    console.log('myfile:');
    console.log(content);
})

// using waitFor
// receive post data
http.createServer(80, function(req, res) {
    async function handleRequest(req, res) {
        if (req.method === 'POST') {
            req.body = await waitFor(req.sock, 'data');
        }

        // now you can do something with req.body
    }
})

Be attention, waitFor the data or stream event will make this function add listener to data, end and error events. All data will be returned only if there is no error event triggered and the end event is triggered. As for other event, only the second argument will be passed to the Promise

After v1.1.4, you can pass a context to the promisfy as its second argument. Context will be used as the context of fn, for example:

function callback() {
    console.log(this)
}

promisfy(fs.readFile, fs);

If your callback function expects more than just 2 arguments, the 2nd through nth arguments will be automatically bundled in an array when the promise resolves.

foo(inputArg1, (error,responseArg1,responseArg2,responseArg3) => {})

can be promisfied like this:

var [responseArg1,responseArg2,responseArg3] = await promisfy(foo)(inputArg1)