How to Use Environment Files (.env) in Node.js - Tutorial (dotenv)
Вставка
- Опубліковано 3 жов 2024
- In today's video I'll take you through using .env files in NodeJS - this is done using the popular "dotenv" package.
.env files are used to store environment-specific configuration or settings for your application so it can easily be ran on various environments. Things like database credentials, API keys or URLs for 3rd party resources can be stored in them.
For your reference, check this out:
www.npmjs.com/...
🏫 My Udemy Courses - www.udemy.com/...
🎨 Download my VS Code theme - marketplace.vi...
💜 Join my Discord Server - / discord
🐦 Find me on Twitter - / dcodeyt
💸 Support me on Patreon - / dcode
📰 Follow me on DEV Community - dev.to/dcodeyt
📹 Join this channel to get access to perks - / @dcode-software
If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
#dcode #javascript
Great video!
For those working with ES6 and who could face some trouble, you could use this :
`import dotenv from 'dotenv';
dotenv.config();`
instead of require().
Thanks a ton manhh
another way :
import { config } from 'dotenv'
config()
Thanks 😁
THANKYOUUUUUUUUUUUUUU
Quick and straight to the point! thanks man. You just got a new subscriber!
thanks for the video , just on point. Before watching this video I had to read multiple useless blogs that were long and still were not clear enough and incomplete.
2:27 is when the vid starts
Thanks man. You quickly solved what 5 other videos didn't!
exactly 😂
Great video, short and to the point. Thank you
I really appreciate these vids too, "short and to the point"
simple and straight forward thanks bro
great video and very consistent explanation, thank you, bro!
If your .env is named different like .env.local then you pass the options in config:
config({path: "./.env.local"})
Quick and easy. Thanks a lot!
I LOVE YOU SO MUCH EVERY OTHER VIDEO DIDN'T WORK I LOVE YOU
Thank you so much ! Created my first .env file LOL.
Thank you so much! Help me clear my doubt!!!
You're welcome 😊
FYI: The .env file has to be where you start the application. I had index in /src/index.js, and env '/' and my start script was 'cd src && nodex index.js' and it did not detect my env variables. In the video you said in the root, but not all applications start from the root.
I had the same probleme but I put the .env file in src and requiere dotenv module like this: require(“dotenv”).config({path:”src/.env”});
Was having the same issue, your comment helped me. Thanks!
Actually a great video. Thank you very much
Thank you my brother that was helpful
thank you my friend, helped me a lot !!!
Well Explained, Thanks
Great vid as always
You're welcome.
Thank you, it's useful!
Keep Going My Friend On The Internet 😁
Why do I need the dotenv dependency though? Can't I just add properties to the process.env in a seperate file and import them to the other sheets ?
Thankful for the content you are giving out.
Kindly create a video on how to upload a image or other files with node with a package
Works. Thank you
That was helpful 👍
Great and Thanks Bro 👍👍👍
You are a GOD!!!!!!!!!!!!
Thanks man!
Thanks!
Short Sweet and Effective.
Glad you liked it
thank you so much!
Klick (=like) first, then watch the content ;)))
Excellent content/topic
Thank you!
Thanks!!
nice! ty
thanks budy
thank you
if you're ever having issues with .env. for example if it is saying something like needs to be a string...make sure your .env file is in the root of your project
thnx !
And how do I setup env in production after deployment?..
trying to use a env file in a vite project but getting this: Uncaught ReferenceError: require is not defined
It looks like you have not installed packages
How do we get the cloud foundry env variables like VCAP_APPLICATION in node.js ?
Thank you! This was awesome. Notheless, could you set subtitles in your next videos, please?
I have a problem and also a question. what if I want to use multiple databases in dotenv?
thanks
Mine says "undefined"
Any ideas? Been looking around for 5 hours now. lol. programming is fun.
Same
ty
Starts at 2:28
worked
.env file should be outside of any folder like routes or any other
that solved my undefined problem.
Thanks alot brother you saved my day❤
mine is outside of any folder and i still get undefined :(
which theme are you using?
The theme I'm using is called "dcode" and I made it for my UA-cam videos. You can find it on VS Code marketplace
i wish this worked for me i keep getting undefined
♥️♥️♥️
It could be better if u separated the introduction to .env and the usage guide into two even shorter videos just so people get faster answers from your channel
Don Ports
1) I don't care what your name is.
2) I can read the title of the video, that's why I clicked on it.
thank you!