node
node copied to clipboard
Modules preloading suggestion
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.
Just fyi, you can pass these options through an environment variable: NODE_OPTIONS=-r a.js -r b.js
… does that help you?
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.
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?
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.
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.
Hi, I think it might still be a thing!
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.
Would love to see this as a feature. Might implement it once I have time.
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.
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.