path.resolve()
Resolves a sequence of paths into an absolute path.
Syntax
path.resolve(...paths) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
paths | ...string | Yes | Path segments, processed right to left until an absolute path is formed. |
Returns
string — An absolute, normalized path.
Examples
import { resolve } from 'node:path';
console.log(resolve('src', 'index.js'));
Output
/home/user/project/src/index.js
import { resolve } from 'node:path';
console.log(resolve('/var', 'log', '../www'));
Output
/var/www
Notes
Prepends `process.cwd()` until the result is absolute, so output
depends on the working directory. For paths relative to the current
module use `import.meta.dirname` (Node 20.11+) or `__dirname`.