Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an error or output a warning when --env-file can not be opened. #50536

Closed
virtuallyunknown opened this issue Nov 3, 2023 · 11 comments
Closed
Labels
feature request Issues that request new features to be added to Node.js. good first issue Issues that are suitable for first-time contributors. help wanted Issues that need assistance from volunteers or PRs that need help to proceed.

Comments

@virtuallyunknown
Copy link

What is the problem this feature will solve?

Greetings! Thanks a lot for implementing --env-file directly into Node.

I am currently using Node v20.9.0 on Linux, and if you run node with the --env-file option that points to a file that can't be reached, it still will execute the program as if everything went fine. For example:

node --env-file=non_existing_file.env my_app.js

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

This is not an uncommon scenario that you can find yourself in, and it can occur for various reasons. For example if you are working in a monorepository and the context of the current working directory changes, or if you lack sufficient permissions to open the file.

I think it would be beneficial for developers if an error or a warning was shown if the env file can't be opened.

What alternatives have you considered?

I have been using the dotenv package and currently in the process of migrating to native --env-file instead.

@virtuallyunknown virtuallyunknown added the feature request Issues that request new features to be added to Node.js. label Nov 3, 2023
@github-project-automation github-project-automation bot moved this to Pending Triage in Node.js feature requests Nov 3, 2023
@anonrig anonrig added good first issue Issues that are suitable for first-time contributors. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. labels Nov 5, 2023
@sunil-kumarr
Copy link

sunil-kumarr commented Nov 6, 2023

@anonrig can you assign this issue to me will like to work on this as my first OSS contribution

@ardinugrxha
Copy link
Contributor

hello there,

I want to take this issue :) , and i would like to discuss an issue and some concerns I have. Specifically, I am wondering what my approach should be if the --env-file is not present. we should return an error because the environment file is important. wdyt?

Additionally, I have another question. What if the user wants to use multiple environment files but one of them is missing? Should we provide a warning and continue the process or stop the process? Any ideas are welcome. :)

cc @anonrig

@virtuallyunknown
Copy link
Author

In my personal opinion, it should throw an error. This will be consistent with how the FileSystem module works, for example if you fs.readFile a non-existing file, it will throw. Another example would be the Node CLI, if you call node --watch non_existing_file.js it will also throw.

@ardinugrxha
Copy link
Contributor

Seems good, I will create the PR soon for this issue

@Simplisticbubble
Copy link

Hi, I would like to be involved in solving this issue! (my first issue)

@ardinugrxha
Copy link
Contributor

Cool! Thanks for being interested in this issue, but unfortunately I am already working on this :)

@Simplisticbubble
Copy link

Simplisticbubble commented Nov 13, 2023 via email

@dimonachi
Copy link

Hi, do you need some help with this?

@40oleg
Copy link

40oleg commented Nov 28, 2023

@virtuallyunknown
I suppose this issue can be closed because of the problem was solved in pr above

@anonrig anonrig closed this as completed Nov 28, 2023
@virtuallyunknown
Copy link
Author

@virtuallyunknown I suppose this issue can be closed because of the problem was solved in pr above

Yep for sure.

Amazing work @ardi-nugraha, hats off to you, and I think this will be beneficial to all developers in their future projects! 👏👏👏

@ardinugrxha
Copy link
Contributor

Thanks @virtuallyunknown . I hope so too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. good first issue Issues that are suitable for first-time contributors. help wanted Issues that need assistance from volunteers or PRs that need help to proceed.
Projects
None yet
Development

No branches or pull requests

7 participants