# es6-promisify

> Converts callback-based functions to ES6 Promises

Latest version **7.0.0** (published 2021-05-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install es6-promisify
pnpm add es6-promisify
yarn add es6-promisify
bun add es6-promisify
```

## Health

**Score 28/100 (F)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 7.0.0 |
| Published | 2021-05-26 |
| First published | 2014-04-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/es6-promisify) |
| Module format | ESM + CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 519 |
| Author | Mike Hall |
| Maintainers | mikehall314 |
| Keywords | promise, promises, es6, promisify, es6-promisify |

## Links

- npm: https://www.npmjs.com/package/es6-promisify
- Repository: https://github.com/mikehall314/es6-promisify
- Homepage: https://github.com/mikehall314/es6-promisify#readme
- Issues: http://github.com/mikehall314/es6-promisify/issues
- npm.io page: https://npm.io/package/es6-promisify

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 7.0.0 (latest) — 2021-05-26
- 6.1.1 — 2020-05-04
- 6.1.0 — 2020-03-16
- 6.0.2 — 2019-08-27
- 6.0.1 — 2018-10-20
- 6.0.0 — 2018-01-30
- 5.0.0 — 2016-09-28
- 4.1.0 — 2016-05-19
- 4.0.0 — 2016-04-01
- 3.0.0 — 2015-08-17
- 2.0.0 — 2015-06-15
- 1.1.1 — 2014-09-16
- 1.1.0 — 2014-09-08
- 1.0.2 — 2014-07-30
- 1.0.1 — 2014-06-24
- … 2 more at https://npm.io/package/es6-promisify/versions

## README

![Build Status](https://github.com/digitaldesignlabs/es6-promisify/actions/workflows/test.yml/badge.svg)

# es6-promisify

Converts callback-based functions to Promises, using a boilerplate callback function.

## Install

Install with [npm](https://npmjs.org/package/es6-promisify)

```bash
npm install es6-promisify
```

## Example

```js
const {promisify} = require("es6-promisify");

// Convert the stat function
const fs = require("fs");
const stat = promisify(fs.stat);

// Now usable as a promise!
try {
    const stats = await stat("example.txt");
    console.log("Got stats", stats);
} catch (err) {
    console.error("Yikes!", err);
}
```

## Promisify methods

```js
const {promisify} = require("es6-promisify");

// Create a promise-based version of send_command
const redis = require("redis").createClient(6379, "localhost");
const client = promisify(redis.send_command.bind(redis));

// Send commands to redis and get a promise back
try {
    const pong = await client.ping();
    console.log("Got", pong);
} catch (err) {
    console.error("Unexpected error", err);
} finally {
    redis.quit();
}
```

## Handle multiple callback arguments, with named parameters

```js
const {promisify} = require("es6-promisify");

function test(cb) {
    return cb(undefined, 1, 2, 3);
}

// Create promise-based version of test
test[promisify.argumentNames] = ["one", "two", "three"];
const multi = promisify(test);

// Returns named arguments
const result = await multi();
console.log(result); // {one: 1, two: 2, three: 3}
```

## Provide your own Promise implementation

```js
const {promisify} = require("es6-promisify");

// Now uses Bluebird
promisify.Promise = require("bluebird");

const test = promisify(cb => cb(undefined, "test"));
const result = await test();
console.log(result); // "test", resolved using Bluebird
```

### Tests

Test with tape

```bash
$ npm test
```

Published under the [MIT License](http://opensource.org/licenses/MIT).

---
_Source: https://npm.io/package/es6-promisify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
