Skip to content

Provide a reliable way to find the entrypoint path or URL #51840

Open

Description

@nex3

What is the problem this feature will solve?

This solves the same problem as require.main.filename did in a CommonJS-only world: finding the entrypoint script for the Node.js process. This is most commonly used to determine the whether the current file is the entrypoint, but is also useful for various other sorts of introspection about the running Node.js environment. My specific use-case is finding a sensible default base URL to use to replicate Node.js's package resolution algorithm.

What is the feature you are proposing to solve the problem?

I suggest something like process.cliEntrypoint or process.cliMainUrl. I think it's important that any solution be usable regardless of whether the current module is CJS or ESM.

What alternatives have you considered?

require.main.filename provides this information but it doesn't work outside of CJS files, nor does it work if the entrypoint itself is ESM.

process.argv[1] sometimes provides this information, but it has a number of problems:

  • If the Node.js CLI is run without a file extension, like node myapp instead of node myapp.js, process.argv[1] won't have an extension either.

  • If the entrypoint is a symlink, process.argv[1] will point to the symlink instead of the physical JS file. This differs from __filename, which means it also differs from the logic used by require(). Note that npm exec always creates a symlink when running executables.

  • process.argv is mutable, so it's possible for unrelated code to modify it in such a way that it's no longer usable to find the entrypoint.

Activity

  1. github-actions commented on Aug 21, 2024

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-stale Issues and PRs exempt from automated stale handling. label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment.
    For more information on how the project manages feature requests, please consult the feature request management document.

  2. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Aug 21, 2024
  3. nex3 commented on Aug 21, 2024

    @nex3
    Author

    Please don't close this! It would still be very useful!

  4. removed
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Aug 22, 2024
  5. added
    loadersIssues and PRs related to ES module loaders.
    on Aug 22, 2024
  6. avivkeller commented on Aug 22, 2024

    @avivkeller
    Member

    @nodejs/loaders

  7. moved this from Awaiting Triage to Triaged in Node.js feature requestson Aug 22, 2024
  8. github-actions commented on Feb 19, 2025

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-stale Issues and PRs exempt from automated stale handling. label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment.
    For more information on how the project manages feature requests, please consult the feature request management document.

  9. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Feb 19, 2025
  10. nex3 commented on Feb 19, 2025

    @nex3
    Author

    Again, this would still be extremely useful.

  11. removed
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Feb 20, 2025
  12. github-actions commented on Aug 19, 2025

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-stale Issues and PRs exempt from automated stale handling. label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment.
    For more information on how the project manages feature requests, please consult the feature request management document.

  13. 3 remaining items

  14. jsumners-nr commented on Aug 21, 2025

    @jsumners-nr

    I don't think anyone is going to pick this up. It will advance quicker if you supply a PR.

  15. nex3 commented on Aug 22, 2025

    @nex3
    Author

    I have my own open source project to run, I'm afraid

  16. jsumners-nr commented on Aug 26, 2025

    @jsumners-nr

    I do not believe I suggested you take over running the Node.js project.

  17. shukriadams commented on Aug 26, 2025

    @shukriadams

    @jsumners-nr Adding a new feature to something as complex as NodeJS is hardly a trivial undertaking. That's the sort of thing one would think a core maintainer would pick up, or at least weigh in on. The request itself also seems completely reasonable, I'm here because I was looking for the same thing.

  18. jsumners-nr commented on Aug 26, 2025

    @jsumners-nr

    Directly from the document the bot keeps linking (emphasis added):

    At the same time, the project is volunteer run and does not have the ability to direct resources toward specific work. The features which are implemented are those for which volunteers are individually motivated to work on. The best way to ensure a feature gets implemented is to create a PR to add it. The project strives to support people who do that.

  19. avivkeller commented on Aug 26, 2025

    @avivkeller
    Member

    Are you a NodeJS maintainer?

    Yes, @jsumners-nr is a member of the Node.js project.

  20. jsumners-nr commented on Aug 26, 2025

    @jsumners-nr

    I am participating in the project in a few ways, yes. I started watching this issue because I think it is an interesting one. After several "bump" posts, it became clear the path that needs to happen for this to move forward and so I suggested that path.

  21. nex3 commented on Aug 26, 2025

    @nex3
    Author

    I do not believe I suggested you take over running the Node.js project.

    I do not believe I said you did. Running an open-source project usually precludes spending a bunch of time adding features to upstream dependencies.

  22. thescientist13 commented on Sep 1, 2025

    @thescientist13
    Sponsor

    FWIW, I opened an issue a little while ago inquiring about the NodeJS project adopting some sort of feature bounty program, since I was interested in advancing certain issues / features personally (this one is on the list, just not at the top).

    There are some TSC follow up issues to review as well were more discussions have been happening

    Reception has been mixed (I guess?), but who knows 🤞

  23. crydafan commented on Jan 24, 2026

    @crydafan

    Is this still needed? I'd like to contribute, thank you kindly

  24. mcollina commented on Jan 24, 2026

    @mcollina
    SponsorMember

    Go ahead!

  25. harishn1408 commented on Apr 30, 2026

    @harishn1408
  26. harishn1408 commented on May 6, 2026

    @harishn1408
  27. avivkeller commented on Jul 31, 2026

    @avivkeller
    Member
  28. added a commit that references this issue on Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.loadersIssues and PRs related to ES module loaders.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions