# util-callbackify

> A backport of `util.callbackify` for Node.js 6.0 and up.

Latest version **1.0.0** (published 2018-08-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install util-callbackify
pnpm add util-callbackify
yarn add util-callbackify
bun add util-callbackify
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-08-28 |
| First published | 2018-08-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | linusu |
| Keywords | async, callback, callbackify, cb, convert, depromisify, dethenify, errback, nodeback, nodeify, promise-to-callback, promise, promisify, then, thenify, unpromisify, unthenify |

## Links

- npm: https://www.npmjs.com/package/util-callbackify
- Repository: https://github.com/LinusU/util-callbackify
- Homepage: https://github.com/LinusU/util-callbackify#readme
- Issues: https://github.com/LinusU/util-callbackify/issues
- npm.io page: https://npm.io/package/util-callbackify

## Dependencies (1)

- [object.getownpropertydescriptors](https://npm.io/package/object.getownpropertydescriptors.md) ^2.0.3

## 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

- 1.0.0 (latest) — 2018-08-28

## README

# `util.callbackify`

A backport of `util.callbackify` for Node.js 6.0 and up.

## Installation

```sh
npm install --save util-callbackify
```

## Usage

```js
const callbackify = require('util-callbackify')

async function fn () {
  return 'Hello, World!'
}

const callbackFunction = callbackify(fn)

fn((err, result) => {
  if (err) throw err

  console.log(result)
  //=> Hello, World!
})
```

## API

### `callbackify(original)`

- `original` &lt;Function&gt; An `async` function
- Returns: &lt;Function&gt; a callback style function

Takes an `async` function (or a function that returns a `Promise`) and returns a
function following the error-first callback style, i.e. taking
an `(err, value) => ...` callback as the last argument. In the callback, the
first argument will be the rejection reason (or `null` if the `Promise`
resolved), and the second argument will be the resolved value.

The callback is executed asynchronously, and will have a limited stack trace.
If the callback throws, the process will emit an [`'uncaughtException'`][]
event, and if not handled will exit.

Since `null` has a special meaning as the first argument to a callback, if a
wrapped function rejects a `Promise` with a falsy value as a reason, the value
is wrapped in an `Error` with the original value stored in a field named
`reason`.

```js
function fn() {
  return Promise.reject(null)
}
const callbackFunction = util.callbackify(fn)

callbackFunction((err, ret) => {
  // When the Promise was rejected with `null` it is wrapped with an Error and
  // the original value is stored in `reason`.
  err && err.hasOwnProperty('reason') && err.reason === null // true
})
```

[`'uncaughtException'`]: https://nodejs.org/api/process.html#process_event_uncaughtexception

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