Import-meta-based path utilities for modern Node.js ESM applications.
- Features
- Requirements
- Setup
- Usage
- Development
- Testing
- Troubleshooting
- Security
- API
- Packaging
- Examples
- Support
- Links
- License
- Accept
import.metaor a directory string as the base path. - Join, resolve, and relativize paths with native Node.js behavior.
- Convert paths to file URLs and file URLs to paths.
- Include TypeScript declarations and have no runtime dependencies.
- Node.js 26 or later.
- Native ESM support.
Install the package:
npm install @eliware/pathPass import.meta from an ESM module, or pass a directory string:
import path, { pathUrl, resolvePath, relativePath } from "@eliware/path";
const filePath = path(import.meta, ".env");
const fileUrl = pathUrl(import.meta, "module.mjs");
const absolutePath = resolvePath(import.meta, "data", "input.json");
const relative = relativePath(import.meta, "data", "input.json");Read release notes for package changes.
Read the documentation index for the architecture and operations guides. Read the repository specifications for normative rules. See the example index for runnable examples.
Run aggregate validation:
npm testRun npm run lint, npm run audit, npm run format:check, npm run typecheck, or npm run pack for one check.
Pass import.meta or a directory string to each path helper.
Missing or invalid bases cause an error.
String inputs always represent directories.
These helpers do not access files or networks.
Absolute segments and .. can escape the base path.
Validate untrusted segments before file access.
getCurrentFilename(metaOrDir)returns a module file path or the input directory string.getCurrentDirname(metaOrDir, dirnameFn?)returns the current directory path.path(metaOrDir, ...segments)joins the base directory with path segments.pathUrl(metaOrDir, ...segments)returns a file URL string.resolvePath(metaOrDir, ...segments)returns an absolute path.relativePath(metaOrDir, ...segments)returns a path relative to the base directory.fileUrlToPath(fileUrl)converts a file URL to a path.
The default export is path. All helpers accept ImportMeta or a directory string.
The optional dirnameFn applies only to ImportMeta inputs.
The package uses native ESM and supports Node.js 26 or later.
It includes TypeScript declarations under src/.
It has no runtime dependencies and performs no initialization at import time.
Run the example from the repository root:
node examples/example.mjsSee examples/README.md for the full example index.
For help, questions, or to chat with the author and community, visit:


