Home / Companies / Sonar / Blog / Post Details
Content Deep Dive

__dirname is back in Node.js with ES modules

Blog post from Sonar

Post Details
Company
Date Published
Author
Phil Nash
Word Count
911
Company Posts That Month
8
Language
English
Hacker News Points
3
Post removed?
No
Summary

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.

Trends Found in this Post

No tracked trend matches for this post yet.

Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.