Skip to content

Instantly share code, notes, and snippets.

@isuvorov
Created April 18, 2024 05:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isuvorov/542c7c1b3ed140da13c8242c6316dcee to your computer and use it in GitHub Desktop.
Save isuvorov/542c7c1b3ed140da13c8242c6316dcee to your computer and use it in GitHub Desktop.
ESM __dirname and __filename
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
export const getFilename = (meta) => fileURLToPath(meta.url);
export const getDirname = (meta) => dirname(getFilename(meta));
const __filename = getFilename(import.meta);
const __dirname = getDirname(import.meta);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment