node icon indicating copy to clipboard operation
node copied to clipboard

Modules preloading suggestion

Open zaguiini opened this issue 5 years ago • 8 comments

Is your feature request related to a problem? Please describe. Not exactly a problem. Maybe something that will make life easier. Currently to require modules before executing a script we need to run node with the -r flag and it might become harder to maintain if we need to require multiple modules.

People usually use this option like a "bootstraper" or for running setup scripts (i.e. dotenv/config).

Describe the solution you'd like I'd like to have a place to specify, in order and separated by a new line, the modules needed to be required before executing scripts. Something like:

dotenv/config
tsconfig-paths/register

And then something like that to run scripts:

node --requirements-file requirements.txt my-script.js

We could even maybe ignore the flag altogether if the requirements file -- which has yet to be named -- exists.

Describe alternatives you've considered I'm doing something sorta like that on this repository of mine. Take a look.

zaguiini avatar Feb 15 '20 18:02 zaguiini

Just fyi, you can pass these options through an environment variable: NODE_OPTIONS=-r a.js -r b.js… does that help you?

addaleax avatar Feb 15 '20 18:02 addaleax

Thanks for the help, @addaleax!

You're still needing to pass it on the command line and repeating -r before each import (and if you accidentally omit -r it will silently fail).

Personally I don't like commands to be lengthy, that's why I'm proposing this, to make it cleaner.

zaguiini avatar Feb 15 '20 19:02 zaguiini

Thinking one step further, I think if we were to implement something like this, it should be a file that lists generic options, not just requires; e.g. node --options-file=foo where foo might contain something like

-r require1.js
-r require2.js
--pending-deprecation

… Thoughts?

addaleax avatar Feb 15 '20 19:02 addaleax

That'd be nice! It'd be even nicer if we were able to provide an override mechanism such as still accept CL arguments while simultaneously passing the --options-file flag. 10/10 would use it.

zaguiini avatar Feb 15 '20 19:02 zaguiini

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be 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.

github-actions[bot] avatar Mar 08 '22 13:03 github-actions[bot]

Hi, I think it might still be a thing!

zaguiini avatar Mar 08 '22 14:03 zaguiini

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be 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.

github-actions[bot] avatar Sep 15 '22 01:09 github-actions[bot]

Would love to see this as a feature. Might implement it once I have time.

zaguiini avatar Sep 21 '22 02:09 zaguiini

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be 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.

github-actions[bot] avatar Mar 22 '23 01:03 github-actions[bot]

The project is traditionally not very fond of adopting config files so that's probably why your feature request didn't see any uptake. Given that it's been open for over 3 years ago, I'll go ahead and close it. Thanks for the suggestion though.

bnoordhuis avatar Mar 22 '23 08:03 bnoordhuis