镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

@virtuallyunknown

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.

Activity

  1. added
    good first issueIssues that are suitable for first-time contributors.
    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.
    on Nov 5, 2023
  2. sunil-kumarr commented on Nov 6, 2023

    @sunil-kumarr

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

  3. arxngr commented on Nov 6, 2023

    @arxngr
    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

  4. virtuallyunknown commented on Nov 6, 2023

    @virtuallyunknown
    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.

  5. arxngr commented on Nov 6, 2023

    @arxngr
    Contributor

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

  6. Simplisticbubble commented on Nov 13, 2023

    @Simplisticbubble

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

  7. arxngr commented on Nov 13, 2023

    @arxngr
    Contributor

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

  8. Simplisticbubble commented on Nov 13, 2023

    @Simplisticbubble
  9. dimonachi commented on Nov 19, 2023

    @dimonachi

    Hi, do you need some help with this?

  10. 40oleg commented on Nov 28, 2023

    @40oleg

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

  11. virtuallyunknown commented on Nov 28, 2023

    @virtuallyunknown
    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! 👏👏👏

  12. arxngr commented on Nov 28, 2023

    @arxngr
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.good first issueIssues that are suitable for first-time contributors.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions