Created
September 22, 2021 08:02
-
-
Save bichotll/7b4574a1d432ea370d8141cded11018e to your computer and use it in GitHub Desktop.
__dirname and __filename in ESM node
This file contains 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 { 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