Dotenv

Dev tools

environment variable loader

SHOW HN2024

225points
100comments
#338of 3,515 in 2024
Top 10%of 2024 by points

How HN took it

RoastedHalf or more of the comments are critical

2 positive, 6 neutral or asking, 0 mixed, 12 critical, out of 20 comments about the project. Thread score -0.44.

Idea: 2 for, 11 againstDocs: 0 for, 1 against

The thread, comment by comment

Each row is a top-level comment and its replies, in HN's order. Select a cell to open that comment on HN.

positive neutral or mixed critical about another commenter or something else the maker

What HN said

What people liked

  • Explicit invocation avoids hidden environment behavior

    From 1 comment
    • I've used direnv, but I think a nice property of OP's dotenv is that it's explicit: if I want to pass env vars, I run my program under it. If I don't, then I don't. There's no…
      kelnos on HN

Objections

  • Sourcing .env in shell is simpler and already works

    From 3 comments
    • Would not sh -c '. .env; echo $MY_VAR' do the same thing? (I am not in front of a shell at the moment.)
      mongol on HN
    • Please just see this `env -S "$(cat .env)" <cmd>` Believe it or not that’s all you need. > S, --split-string=S process and split S into separate arguments; used to pass multiple…
      tuyiown on HN
    • I don't understand what more it does than sourcing a file on your shell would? Anyone can explain?
      prmoustache on HN
  • Existing tools like direnv and dotenvx already cover this

    From 2 comments
    • I think direnv already does a good job in this space, and it's already available in your package manager. https://direnv.net/
      petepete on HN
    • Compare with dotenvx - https://github.com/dotenvx/dotenvx This is my current tool of choice.
      grounder on HN
  • Whitespace and comment handling breaks naive env $(cat .env) approaches

    From 3 comments
    • This will fail with comments. Of course you can script around that as well (I have done so), but it's not bulletproof. It makes sense to have a dedicated tool for the job.
      ibotty on HN
    • Has whitespace handling issues... but valiant effort!
      arjvik on HN
    • When your environment variable values have spaces (e.g. some connection strings) this doesn’t work iirc
      fire_lake on HN

Requests

  • Compatibility with Docker env file format

    From 1 comment
    • Does this accept the exact same format (including quotes and whitespace) as a Docker env file? That’s a key feature for me
      fire_lake on HN

Questions

  • What does it do beyond sourcing a file in the shell

    From 1 comment
    • I don't understand what more it does than sourcing a file on your shell would? Anyone can explain?
      prmoustache on HN

Alternatives named

  • direnv

    From 1 comment
    • I think direnv already does a good job in this space, and it's already available in your package manager. https://direnv.net/
      petepete on HN
  • dotenvx

    From 1 comment
    • Compare with dotenvx - https://github.com/dotenvx/dotenvx This is my current tool of choice.
      grounder on HN
  • shdotenv

    From 1 comment
    • There is also shdotenv that allows you to load different .env file formats and convert between them, e.g. for UNIX shell. https://github.com/ko1nksm/shdotenv
      miohtama on HN
  • dotenv-cli npm package

    From 1 comment
    • Doesn’t this already exist as https://www.npmjs.com/package/dotenv-cli ?
      vishvananda on HN

Category, keywords, summaries and labels on this page were made by AI (Thread Reader v2) and not checked by hand. Each point links to the comments it came from.

Add a badge to your READMEShown on HackerShow
[![Shown on HackerShow](https://hackershow.org/badge.svg)](https://hackershow.org/show/40191510)