Created
January 26, 2022 03:04
-
-
Save justsml/a9e65238baa311c2b202380111881fa5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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