Skip to content

Documentation for __dirname is misleading #5525

Closed
@c-f-h

Description

@c-f-h

The documentation for __dirname states that it gives "The name of the directory that the currently executing script resides in."

This may be taken to imply that __dirname always refers to the path of the module that was invoked as a script from the command line. However, it actually always produces the path of the current module, no matter where it was required from.

Just to clarify: assume I have modules

a.js
b/b.js

and a.js requires b.js. I run node a.js, and b.js uses its __dirname, which will refer to the b subdirectory. The current wording implies that it might actually refer to the directory that a.js is contained in since that is the "script" that I ran from the command line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.moduleIssues and PRs related to the module subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions