__dirname is back in Node.js with ES modules

Open link in next tab

__dirname is back in Node.js with ES modules

https://www.sonarsource.com/blog/dirname-node-js-es-modules/

Node.js is reducing friction when using ES modules by making it easier to get the current module directory name

__dirname is back in Node.js with ES modules

cross-posted from: https://programming.dev/post/11927506

Many times when I’ve tried to write some code in Node.js using ES modules I’ve found myself reaching for __dirname and then looking up how to replace it. Now Node.js, Deno and Bun support import.meta.dirname. Check out the article for more detail.