Compatibilidade APIs Node.js - Utils
O módulo util
no Node.js fornece um conjunto de funções utilitárias que auxiliam em várias tarefas, aprimorando a funcionalidade de aplicações JavaScript e Node.js. Ele é particularmente útil para desenvolvedores que buscam simplificar tarefas de programação comuns e melhorar a legibilidade do código.
/** * An example of using Node.js Util API in an Azion Edge Function. * Support: * - Partially supported (Extended by library `util`) * @module runtime-apis/nodejs/util/main * @example * // Execute with Azion Bundler: * npx edge-functions build * npx edge-functions dev */import util from "node:util";
const myTest = (callback) => { try { callback(null, "Success!"); } catch (err) { callback(err); }};
/** * An example of using the Node.js Util API in an Azion Edge Function. * @param {*} event * @returns {Promise<Response>} */const main = async (event) => { const promisifyTest = util.promisify(myTest); const result = await promisifyTest(); console.log(util.inspect(result, { showHidden: false, depth: null }));
return new Response("Done!", { status: 200 });};
export default main;
Contribuidores