Skip to content

Instantly share code, notes, and snippets.

@remino
Created October 25, 2021 05:50
Show Gist options
  • Save remino/b6c11232786d7b38f44ba8c1b5a4650e to your computer and use it in GitHub Desktop.
Save remino/b6c11232786d7b38f44ba8c1b5a4650e to your computer and use it in GitHub Desktop.
Get __filename & __dirname in Node native ES modules
// Get __filename & __dirname in Node native ES modules
import { URL } from 'url'
const __filename = new URL('', import.meta.url).pathname
const __dirname = new URL('.', import.meta.url).pathname
console.log(__filename)
console.log(__dirname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment