Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

16
  • 6
    What are the advantages of this solution over path.dirname(process.argv[1])? Commented Dec 18, 2018 at 5:42
  • 44
    @DanDascalescu __dirname is not the process directory path, it is the path of the current module's directory. Commented Dec 18, 2018 at 6:06
  • 4
    This didn't work for me under Linux. Anyone else experienced the same problem? Commented Mar 15, 2019 at 7:26
  • 3
    On Windows (untested on other platforms) this solution results in a leading `` character in the path, which breaks quite a bit of stuff. I can trim it to resolve the issue, but I'm not sure if that solution is cross-platform compatible. Commented Mar 23, 2019 at 8:16
  • 3
    Perhaps it doesn't require creating multiple files, but it does require duplicating these three lines of code in every module that wants to use __dirname. That's ugly. Is there really no better solution for --experimental-modules? Commented Nov 28, 2020 at 16:58