Path
path.dirname()
Finds the directory portion of a path without checking whether it exists. Tested on Node.js 22.16.0. A bare filename has dirname dot; a root remains a root.
Formal Syntax & Structure
nodejs syntaxnodejs
path.dirname(path)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| path | string | Path text. |
Return Value
string
Parent path text.
Working Example
Example Snippetnodejs
import path from 'node:path';console.log(path.posix.dirname('/catalog/report.csv'));