Skip to content

Instantly share code, notes, and snippets.

@Asjas
Created February 16, 2021 21:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Asjas/2816b1a4ee91262f45f644c37da62a9b to your computer and use it in GitHub Desktop.
Save Asjas/2816b1a4ee91262f45f644c37da62a9b to your computer and use it in GitHub Desktop.
Node.js ES modules __dirname and __filename
import { fileURLToPath } from 'url';
import { dirname } from 'path';
console.log(`import.meta.url: ${import.meta.url}`);
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
console.log(`dirname: ${__dirname}`);
console.log(`filename: ${__filename}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment