URL

fileURLToPath()

Converts a file URL into a filesystem path with percent decoding and platform rules. Tested on Node.js 22.16.0. Do not substitute URL.pathname for file conversion; conversion does not authorize file access.

Formal Syntax & Structure

nodejs syntaxnodejs
fileURLToPath(url[, options])

Parameters & Attributes

NameTypeDescription
urlURL | stringFile URL.
optionsobjectOptional windows selector (default platform).

Return Value

string

Filesystem path.

Working Example

Example Snippetnodejs
import { URL, URLSearchParams, fileURLToPath, pathToFileURL } from 'node:url';console.log(fileURLToPath('file:///catalog/my%20book.txt',{windows:false}));
Node.js Reference