node:path
The node:path module in Azion Runtime: functions that join, parse, and normalize path strings, examples for routing and parsing, and the supported APIs.
The node:path module provides the Node.js utilities for working with file and directory paths. Its functions join, split, normalize, and parse paths, and a function uses them to build paths when it routes requests or composes asset references. Azion Runtime does not give a function access to a real filesystem, so every path function operates on path strings only. For example, path.resolve() returns a string without reading a directory.
Examples
The functions below run on their own: each one imports path from node:path, and each output is the one a deployed function returns.
Basic path operations
This function joins three segments into one path, logs it, and returns it in the response body:
The function logs Path /images/image.jpg and responds with this body:
URL routing with path
This function splits the request path into its directory, file name, and extension, then builds an API path and an absolute path from the parts:
For a request to /docs/getting-started, a path with no file extension, the function responds with each part of the path and the two paths it built:
Path normalization and parsing
This function normalizes a path that holds .., ., and a double slash. It then parses a path into its parts, builds a path from an object, and checks whether two paths are absolute:
The function responds with the normalized path, the parsed parts, the formatted path, and the two checks:
Path separators and platform variants
This function joins the same segments with the default, POSIX, and Windows variants of the module, and reads each separator and the delimiter:
The function responds with the same joined path and the / separator for all three variants, and : as the delimiter:
Supported APIs
The table lists the status of each node:path API in Azion Runtime:
| API | Status |
|---|---|
path.basename() | 🟢 Supported |
path.dirname() | 🟢 Supported |
path.extname() | 🟢 Supported |
path.format() | 🟢 Supported |
path.isAbsolute() | 🟢 Supported |
path.join() | 🟢 Supported |
path.normalize() | 🟢 Supported |
path.parse() | 🟢 Supported |
path.relative() | 🟢 Supported |
path.resolve() | 🟢 Supported |
path.sep | 🟢 Supported |
path.delimiter | 🟢 Supported |
path.posix | 🟢 Supported |
path.win32 | 🟡 Partially supported |
path.win32.join() joins segments with /, so path.win32.join("C:\\a", "b") returns C:/a/b, and path.win32.sep is /.
Every path function operates on path strings, without filesystem access. path.resolve() resolves relative segments against /, so path.resolve("a", "b") returns /a/b. To work with the path of a request, read it with the Web URL API, as in new URL(event.request.url).pathname, and pass it to the node:path functions.