Tweakr
    Preparing search index...

    Function promisify

    • Converts a Node.js-style callback function into a function that returns a Promise.

      Parameters

      • fn: Function

        A function that expects a callback as its last argument (err, result).

      Returns (...args: any[]) => Promise<unknown>

      A function that returns a Promise resolving with the result or rejecting with the error.

      const fs = require("fs");
      const readFileAsync = promisify(fs.readFile);
      readFileAsync("path/to/file.txt", "utf-8").then(console.log);

      1.1.0