Convert a filesystem path to a file:// URL.
function
pathToFileURL
@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.
The
toString()
method on theURL
object returns the serialized URL. The value returned is equivalent to that of href and toJSON.