Utilities

util.callbackify()

Adapts an async or promise-returning function to an error-first callback interface. Callbacks run asynchronously. A rejected falsy reason is wrapped as an Error; use ordinary Error objects for failures. Tested on Node.js 22.16.0. Example output (one line per entry): ["8"].

Formal Syntax & Structure

nodejs syntaxnodejs
util.callbackify(original)

Parameters & Attributes

NameTypeDescription
originalFunctionPromise-returning function.

Return Value

Function

Callback-style adapter.

Working Example

Example Snippetnodejs
import { callbackify } from 'node:util';const f = callbackify(async (n) => n * 2);await new Promise((resolve, reject) => f(4, (err, value) => { if (err) {    reject(err);    return;} console.log(value); resolve(); }));
Node.js Reference