The url module in Node.js provides utilities for URL resolution and parsing. It allows developers to work with URLs in a structured way, making it easier to manipulate and extract information from them. This module is essential for web applications that need to handle URLs for routing, API requests, and more. It’s available in the Azion Runtime through Node.js compatibility, so functions can parse the incoming request URL, read query parameters, and build new URLs when proxying or redirecting traffic.

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

/**
* An example of using Node.js URL API in an Azion Function.
* Support:
* - Partially supported (Extended by library `url`)
* @module runtime-apis/nodejs/url/main
* @example
* // Execute with Azion Bundler:
* npx edge-functions build
* npx edge-functions dev
*/
import url from "node:url";
/**
* An example of using the Node.js URL API in an Azion Function.
* @param {*} event
* @returns {Promise<Response>}
*/
const main = async (event) => {
/**
* URL globalThis object
* https://developer.mozilla.org/en-US/docs/Web/API/URL
* if use URL in the browser, don't need to import
*/
const newUrl = new URL("https://example.com/some/path?format=json&page=1");
console.log("newURL", newUrl);
const urlFormated = url.format({
protocol: "https",
hostname: "example.com",
pathname: "/some/path",
query: {
page: 1,
format: "json",
},
});
console.log(url.parse(urlFormated));
return new Response("Done!", { status: 200 });
};
export default main;