The module API in Node.js is a built-in module that provides functionalities for working with JavaScript modules. It’s essential for managing the modular structure of Node.js applications, allowing developers to organize code into reusable components. This module is available in the Azion Runtime through Node.js compatibility, where it’s typically used to inspect the module system, such as listing the built-in modules available to a function.

The example below shows how to use the module module in a function:

/**
* An example of using the Node.js Module API in an Azion Function.
* Support:
* - Partially supported
* @module runtime-apis/nodejs/module/main
* @example
* // Execute with Azion Bundler:
* npx edge-functions build
* npx edge-functions dev
*/
import module from "node:module";
/**
* An example of using the Node.js Module API in an Azion Function.
* @param {*} event
* @returns {Promise<Response>}
*/
const main = async (event) => {
return new Promise((resolve, reject) => {
module.builtinModules.forEach((moduleName) => {
console.log(moduleName);
});
resolve(new Response("Done"));
});
};
export default main;