Closed Whats-A-MattR closed 3 months ago
I'm not a huge fan of recommending dotenv
, it might be helpful for beginners and local/rapid development, but people tend to forget what are environment variables and it leads to not understanding how to setup them correctly when there is no .env
file (in a VM, on a hosting platform, etc).
I would actually advocate to remove the dotenv
from this doc and use a process.env
instead, so people can use their own environment variable strategy (parsing with zod
, using invariant
or t3-env
, etc.).
What do you think?
dotenv still works where there isn't an env file, at least is my understanding and experience thus far. the method described just adds coverage, mostly for beginners, to override with the contents of a named environment file.
Using a naked process.env
call would lead to more confusion amongst beginners, where more experienced devs using more advanced methods would likely know enough to roll their own solution as opposed to copy pasting the snippet and then getting stuck when it didn't work - leading to raising issues or jumping in discord.
It seems that this is mostly common among people using frameworks like Next, Astro etc. These frameworks say to use a .env.local file in their docs. In the app, this is fine as the app knows about this convention, but Studio doesn't, and causes errors to be thrown for these users when trying to launch studio - which is probably what they're doing before writing any queries in app to confirm their db looks the way they expected.
Hey @Whats-A-MattR @alcpereira
Thank you both very much for this detailed conversation, and the suggested changes to docs regarding the use of process.env
@Whats-A-MattR 🙏🏻
Right now I would prefer we didn't prescribe the dotenv
solution in docs, but instead have an example inside our tursodatabase/examples
repo (which I'm going to rehaul soon) where we can have a ts-dotenv
example.
Some frameworks (and now Node itself, with a flag) known how to read process.env
values, which for anyone new to Node/Typescript, is more likely to come across this.
If we did want to remove process.env
from our examples, I would suggest we update everything to just use an empty string, which we did have until recently — "..."
. We had some feedback that this wasn't clear it was an environment variables (or could be) so I decided to use process.env
, which is inline with a lot of other documentation.
So, action items going forward:
ts-dotenv
exampleHey @Whats-A-MattR @alcpereira
Thank you both very much for this detailed conversation, and the suggested changes to docs regarding the use of
process.env
@Whats-A-MattR 🙏🏻Right now I would prefer we didn't prescribe the
dotenv
solution in docs, but instead have an example inside ourtursodatabase/examples
repo (which I'm going to rehaul soon) where we can have ats-dotenv
example.Some frameworks (and now Node itself, with a flag) known how to read
process.env
values, which for anyone new to Node/Typescript, is more likely to come across this.If we did want to remove
process.env
from our examples, I would suggest we update everything to just use an empty string, which we did have until recently —"..."
. We had some feedback that this wasn't clear it was an environment variables (or could be) so I decided to useprocess.env
, which is inline with a lot of other documentation.So, action items going forward:
- Close this PR
- Create a
ts-dotenv
example- Consider linking where applicable to handling environment variables on all guides (astro, remix, next) do them differently.
Thanks @notrab , on it.
Minor update to address errors faced by some users copy pasting the drizzle.config.ts snippet directly while using a named environment file.
It's currently 2am and it tripped me up for long enough to check the Discord help channel before realising I had to configure dotenv to look at my .env.local file. I noticed that at least one other person hit the same errors, so responded to their request and adding an update here.
Note: the errors from Drizzle complain about url and authToken options being missing, not invalid - which I think is the source of the confusion. I'll get in contact with the Drizzle guys to see if we can get a better error, but the small article amendment is, I think, a good stop-gap for now.
Thanks!