Path
path.parse()
Splits a path into root, dir, base, ext and name fields. Tested on Node.js 22.16.0. Use parse when displaying filename metadata; it does not inspect the actual file.
Formal Syntax & Structure
nodejs syntaxnodejs
path.parse(path)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| path | string | Path text. |
Return Value
object
Five string fields.
Working Example
Example Snippetnodejs
import path from 'node:path';console.log(JSON.stringify(path.posix.parse('/catalog/archive.tar.gz')));