Skip to content

Instantly share code, notes, and snippets.

@bichotll
Created September 22, 2021 08:02
Show Gist options
  • Save bichotll/7b4574a1d432ea370d8141cded11018e to your computer and use it in GitHub Desktop.
Save bichotll/7b4574a1d432ea370d8141cded11018e to your computer and use it in GitHub Desktop.
__dirname and __filename in ESM node
import { URL } from 'url'; // in Browser, the URL in native accessible on window
const __filename = new URL('', import.meta.url).pathname;
// Will contain trailing slash
const __dirname = new URL('.', import.meta.url).pathname;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment