# promisify-node

> Wrap Node-callback functions to return Promises.

Latest version **0.5.0** (published 2018-06-05) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2018-06-05 |
| First published | 2014-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/promisify-node) |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 17.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 145 |
| Author | Tim Branyen |
| Maintainers | johnhaley81, tbranyen |

## Links

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

## Dependencies (2)

- [object-assign](https://npm.io/package/object-assign.md) ^4.1.1
- [nodegit-promise](https://npm.io/package/nodegit-promise.md) ^4.0.0

## Recent versions

- 0.5.0 (latest) — 2018-06-05
- 0.4.0 — 2016-03-11
- 0.3.0 — 2015-11-18
- 0.2.1 — 2015-08-20
- 0.2.0 — 2015-08-20
- 0.1.5 — 2014-11-26
- 0.1.4 — 2014-11-26
- 0.1.3 — 2014-11-26
- 0.1.2 — 2014-04-13
- 0.1.1 — 2014-04-12

## README

Promisify Node
--------------

**Stable: 0.5.0** 

[![Build
Status](https://travis-ci.org/nodegit/promisify-node.png?branch=master)](https://travis-ci.org/nodegit/promisify-node)

Maintained by Tim Branyen [@tbranyen](http://twitter.com/tbranyen).

Wraps Node modules, functions, and methods written in the Node-callback style
to return Promises.

### Install ###

``` bash
npm install promisify-node
```

### Examples ###

Wrap entire Node modules recursively:

``` javascript
var promisify = require("promisify-node");
var fs = promisify("fs");

// This function has been identified as an asynchronous function so it has
// been automatically wrapped.
fs.readFile("/etc/passwd").then(function(contents) {
  console.log(contents);
});
```

Wrap a single function:

``` javascript
var promisify = require("promisify-node");

function async(callback) {
  callback(null, true);
}

// Convert the function to return a Promise.
var wrap = promisify(async);

// Invoke the newly wrapped function.
wrap().then(function(value) {
  console.log(value === true);
});
```

Wrap a method on an Object:

``` javascript
var promisify = require("promisify-node");

var myObj = {
  myMethod: function(a, b, cb) {
    cb(a, b);
  }
};

// No need to return anything as the methods will be replaced on the object.
promisify(myObj);

// Intentionally cause a failure by passing an object and inspect the message.
myObj.myMethod({ msg: "Failure!" }, null).then(null, function(err) {
  console.log(err.msg);
});
```

Wrap without mutating the original:
```javascript
var promisify = require("promisify-node");

var myObj = {
  myMethod: function(a, b, cb) {
    cb(a, b);
  }
};

// Store the original method to check later
var originalMethod = myObj.myMethod;

// Now store the result, since the 'true' value means it won't mutate 'myObj'.
var promisifiedObj = promisify(myObj, undefined, true);

// Intentionally cause a failure by passing an object and inspect the message.
promisifiedObj.myMethod({ msg: "Failure!" }, null).then(null, function(err) {
  console.log(err.msg);
});

// The original method is still intact
assert(myObj.myMethod === originalMethod);
assert(promisifiedObj.myMethod !== myObj.myMethod);
```

### Tests ###

Run the tests after installing dependencies with:

``` bash
npm test
```

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