Dev Helpers
← Back

Encode a filename as a URL

Encode a filename as a URL using Node.js.

Open this example in the interactive library

Source code

import {
  URL,
  domainToASCII,
  domainToUnicode,
  pathToFileURL,
  fileURLToPath,
} from "node:url";
console.log(pathToFileURL("/tmp/report #1.txt", { windows: false }).href);

Sample output

file:///tmp/report%20%231.txt