Last active
October 16, 2023 06:34
-
-
Save wmakeev/b4f511ed02b91d3382fbc1dcb8b54cf0 to your computer and use it in GitHub Desktop.
[ESM __dirname] #esm #dirname #filename #node
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 * as url from "node:url"; | |
/** | |
* Returns `__dirname` like value for ESM | |
* | |
* ```js | |
* const dirname = getDirname(import.meta.url) | |
* ``` | |
* @link https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/ | |
* @param {string} fileUrl | |
*/ | |
export const getDirname = (fileUrl) => url.fileURLToPath(new URL(".", fileUrl)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment