You DON'T NEED Dotenv to Handle Environment Variables in Node.js Anymore!

preview_player
Показать описание
Node 20.6.0 now has a built-in feature for incorporating environment variables without having to install an external package like dotenv.

**DISCORD**

**STAY IN TOUCH 👋**

**QUESTIONS ABOUT MY SETUP**
Рекомендации по теме
Комментарии
Автор

No need for nodemon, no need for dotenv... keeps getting better >:D

FireGames
Автор

Thanks really helped! It also works with tsx when running a typescript file as a script in NextJS. Just add the same command: "tsx --env-file .env.local ${file path}"

michaelxaviercanonizado
Автор

Thank you for the tip! I used NVM but it always messed up the packages when I wanted to update the versions. I started using scoop package manager which is awesome, you can use as many node version as you want, it handles their packages very well, it's really easy to update the versions. At work I use 18, 20 LTS and the latest 21. I ended up installing other developer tools like Git by scoop because it's much more easier to update than using a windows installer.

PeterVatler-hvnf
Автор

Thank you very useful also the nvm part as I was struggling between my node version with yarn it was always selecting the last one which I didn’t want. Thank you very good features 👍

christopheanfry
Автор

Still surprises me that this was not in Node since v1, but still, good to finally have it.

Kinda wondering why the default behaviour isn't to pick up .env & the flag is only required if you want to using another filename.. i.e that is what dotenv has been doing all these years (though, I actually prefer env-var package, mostly)

everyhandletaken
Автор

That cursor flashing animation is wild

JohnMcclaned
Автор

vary help full video now i am using like that in package.json file
"scripts": {
"start": " nodemon --env-file .env ./index.js"
},
any more way to do this then replay me any one 🙋‍♂🙋‍♂

nitishsingh
Автор

If you are using ts, you would use ts-node. But I don't think ts-node support --watch or --watch-path

booi_mangang
Автор

A question: This works from command line (and thus in CI) but if I want to run a piece of code (say tests) from an IDE (such as VSCode), what would be required to load the env variables?

powertester
Автор

This is great thanks! Question I don’t use .env file locally, I add whatever variable I need in windows environment variables (for security reasons, don’t want to commit api keys or whatever by mistake) and simply call them in my apps using dotenv (process.env.someVariable). Is there a way to access these with some other flag such as the one you showed —env-file .env ? Thanks again for video

Jajatar
Автор

Volta is also a really good nvm alternative.

babyboie
Автор

Still going to stick onto dotenv unless env files can be mentioned in package.json to load envs

otakugamingyt
Автор

I have a question. Looking at the folder structure, the .env is inside the the src folder with index.js. When you using the terminal to load the dotevn, is it absolute to write the file that needs the environment variables it in each case ? Or is something to be loaded once and the whole app starts using it ?

amadikesullivan
Автор

Can anyone tell me which theme & font is that

adarshchakraborty
Автор

Definitely going to ditch dotenv now. Have you tried out Remix?

CapChunks
Автор

Will an api key be exposed on the frontend using this method?

losVamonos
Автор

not sure how can the production code will read the environment

surendramaran
Автор

How does your command prompt suggest stuff?

egwuted
Автор

Use typescript. You will realize why dotenv is needed. Make videos if you have proven solution for all usecases, instead of just gaining attraction.

shubhampatil
Автор

To long and feels overlay complicated explanation about this

ThomazMartinez