Dev Helpers
← Back

Convert a promise to a callback

Convert a promise to a callback using Node.js.

Open this example in the interactive library

Source code

import * as util from "node:util";
console.log(
  await new Promise((resolve) =>
    util.callbackify(async () => 42)((err, value) => resolve(value)),
  ),
);

Sample output

42