Node.js API compatibility - Utils

The util module in Node.js provides a set of utility functions that assist with various tasks, enhancing the functionality of JavaScript and Node.js applications. It’s particularly useful for developers looking to simplify common programming tasks and improve code readability.

/**
* 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;

Contributors