pathToFileURL

Bun

Symbol

pathToFileURL

function pathToFileURL(path: string): URL

Convert a filesystem path to a file:// URL.

@param path

The path to convert.

@returns

A URL with the file:// scheme.

const url = Bun.pathToFileURL("/foo/bar.txt");
console.log(url.href); // "file:///foo/bar.txt"

Internally, this function uses WebKit's URL API to convert the path to a file:// URL.

Referenced types

class URL

The URL interface represents an object providing static methods used for creating object URLs.

MDN Reference