Last active
April 19, 2024 08:18
-
-
Save carlotrimarchi/b7f33abdb565e050de8683c1176e604e to your computer and use it in GitHub Desktop.
__dirname and absolute path in Node v20, with ESM
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 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