Skip to content

Instantly share code, notes, and snippets.

@carlotrimarchi
Last active April 19, 2024 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlotrimarchi/b7f33abdb565e050de8683c1176e604e to your computer and use it in GitHub Desktop.
Save carlotrimarchi/b7f33abdb565e050de8683c1176e604e to your computer and use it in GitHub Desktop.
__dirname and absolute path in Node v20, with ESM
import path from 'path';
import { fileURLToPath } from 'url';
// get the path of the current file
const __filename = fileURLToPath(import.meta.url);
// get the current directory
const __dirname = path.dirname(__filename);
const absolutePath = __dirname + "/" + "somePicture.jpg";
console.log(absolutePath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment