The path module in Node.js provides utilities for working with file and directory paths. It offers a set of functions that help developers manipulate and normalize paths, making it easier to handle file system operations across different operating systems. This module is available in the Azion Runtime through Node.js compatibility, and it’s commonly used in functions to build or normalize paths, for example when routing requests or composing asset references.
The example below shows how to use the path module in a function:
/** * An example of using the Node.js Path API in an Azion Function. * Support: * - Partially supported (Extended by library `path-browserify`) * @module runtime-apis/nodejs/path/main * @example * // Execute with Azion Bundler: * npx edge-functions build * npx edge-functions dev */import path from "node:path";
/** * An example of using the Node.js Path API in an Azion Function. * @param {*} event * @returns {Promise<Response>} */const main = async (event) => { const pathName = path.join("/", "images", "image.jpg"); console.log("Path", pathName); return new Response(`Path: ${pathName}`);};
export default main;