Skip to content

Instantly share code, notes, and snippets.

@justsml
Created January 26, 2022 03:04
Show Gist options
  • Save justsml/a9e65238baa311c2b202380111881fa5 to your computer and use it in GitHub Desktop.
Save justsml/a9e65238baa311c2b202380111881fa5 to your computer and use it in GitHub Desktop.
import path from "path";
import { fileURLToPath } from "url";
/**
* Usage:
* const { __dirname, __filename } = getFileAndDirname(import.meta.url);
*/
export default function getFileAndDirname(importMetaUrl) {
const __filename = fileURLToPath(importMetaUrl);
const __dirname = path.dirname(__filename);
return { __filename, __dirname };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment