/plushcap/analysis/sonar/dirname-node-js-es-modules

__dirname is back in Node.js with ES modules

What's this blog post about?

ECMAScript (ES) modules are a new standard format for packaging JavaScript code for reuse. There has been a shift from CommonJS to ES modules, but some issues have arisen along the way. One such issue was accessing the current module's directory path. In an ES module, instead of using __dirname or __filename, you can now use import.meta.url. This provides access to the directory path of the current module and allows for file system traversal relative to where your code is located. The way to access this information has evolved over time, from CommonJS's implementation to the latest update in ES modules.

Company
Sonar

Date published
March 21, 2024

Author(s)
Phil Nash

Word count
911

Hacker News points
3

Language
English


By Matt Makai. 2021-2024.