PathAPI
Node API: path
Describes the API provided by the Node API built-in path
module, which supplies utilities for dealing with file and directory paths. Routines are provided for joining, parsing, and extracting bits of information from paths.
Summary
The default implementation of the path
module supplies path logic for the operating system on which the program is currently running; specific implementations for POSIX and Windows are also provided. The module provides utilities for common path operations, including:
basename()
: Extracts the last portion of a path.dirname()
: Extracts the directory portion of a path.extname()
: Extracts the file extension from a path.isAbsolute()
: Determines if a path is absolute.join()
: Joins multiple path segments together.normalize()
: Normalizes a path.parse()
: Parses a path into an object.relative()
: Determines the relative path between two paths.resolve()
: Resolves a sequence of paths or path segments into an absolute path.toNamespacedPath()
: Converts a path to a namespace-prefixed path.format()
: Converts a path object to a path string.
Several configuration properties are also provided, including:
sep
: The path segment separator.delimiter
: The path delimiter.
Specification compliance
This formulation of the Node Path API follows the official definition of the path
module for Node version 21.7.3
, which is current at the time of this writing. The specification for this API can be found here.
Differences in behavior between Node's implementation of this API are usually considered bugs; where this behavior is intentional, it will be noted in this section.
Behavior in Elide
Elide doesn't provide host I/O access by default, and in the case of embedded VFS use, paths are considered under Unix-style rules unconditionally. Most path function implementations use the underlying JVM NIO path utilities.
Further reading
Properties
Provides utilities implementing the NodeAPI for POSIX-style paths, regardless of the current operating system. Paths passed to this instance will forcibly be considered as PathStyle.POSIX-style paths.
Provides utilities implementing the NodeAPI for Windows-style paths, regardless of the current operating system. Paths passed to this instance will forcibly be considered as PathStyle.WIN32-style paths.