Skip to content

Instantly share code, notes, and snippets.

@examosa
Created January 13, 2026 19:28
Show Gist options
  • Select an option

  • Save examosa/aaa2d94a19441527b9afccd596497610 to your computer and use it in GitHub Desktop.

Select an option

Save examosa/aaa2d94a19441527b9afccd596497610 to your computer and use it in GitHub Desktop.
Node.js HTTPS ESM Loader
/**
* Adds support for importing ES modules from the web.
*/
export function load(url, _context, nextLoad) {
if (!url.startsWith("https://")) {
return nextLoad(url);
}
return fetch(url)
.then((res) => res.text())
.then((source) => ({ format: "module", shortCircuit: true, source }));
}
#!/usr/bin/env bash
mapfile -t register <<JS
import { register } from "node:module";
import { pathToFileURL } from "node:url";
register("$XDG_DATA_HOME/node/https-loader.mjs", pathToFileURL("."));
JS
exec node --import "data:text/javascript,${register[*]}" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment