The easiest way to get __dirname in Node with ES Modules
Published on:Getting the directory name (or short for dirname) is extremely simple in Node prior to ES Modules (ESM).
All we had to do was use the __dirname global variable.
console.log(__dirname) // This will show the directory
Unfortunately, __dirname is not supported in ES Modules. So if we want __dirname, we need to use a rather round-about way to retrieve it.