Skip to content

Support query parameters (and hash) in CLI paths #33163

@brettz9

Description

@brettz9

Is your feature request related to a problem? Please describe.

I am interested in having my scripts respond to arguments supplied by the calling file, rather than for the application as a whole (i.e., checking the likes of new URL(import.meta.url).searchParams.get('someParam') rather than process.argv).

This works well when a file imports another. In polyglot files too, it works to get the query string and hash in the browser (Chrome or Firefox at least) no matter whether the import originates in HTML or in JavaScript.

But I get a MODULE_NOT_FOUND error when trying the likes of:

node --experimental-modules  index.mjs?someParam=1

...apparently as it is looking for a file here rather than a (portion of) a URL.

Describe the solution you'd like

Allow the supplied file to be treated as a URL at least as far as the query string and any hash.

Describe alternatives you've considered

It duplicates effort to add special process.argv handling (and it could interfere if the same file is used in an application which has a different root file yet checks process.argv as well as import.meta.url).

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.feature requestIssues that request new features to be added to Node.js.stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions