How to Use Environment Files (.env) in Node.js - Tutorial (dotenv)

preview_player
Показать описание
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:

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().

davidlafontant
Автор

Quick and straight to the point! thanks man. You just got a new subscriber!

edutech
Автор

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.

AMG-ccpi
Автор

simple and straight forward thanks bro

JuanRomero-cqdy
Автор

great video and very consistent explanation, thank you, bro!

vasilymedvedev
Автор

Thanks man. You quickly solved what 5 other videos didn't!

GuilhermeSiebert
Автор

Great video, short and to the point. Thank you

deshangunatunga
Автор

thank you my friend, helped me a lot !!!

sagigalian
Автор

Actually a great video. Thank you very much

XDTrae
Автор

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

patrick_kabwe
Автор

Thank you so much ! Created my first .env file LOL.

kennethsolomon
Автор

I LOVE YOU SO MUCH EVERY OTHER VIDEO DIDN'T WORK I LOVE YOU

danielfan
Автор

Keep Going My Friend On The Internet 😁

bi
Автор

If your .env is named different like .env.local then you pass the options in config:
config({path: "./.env.local"})

peanutcelery
Автор

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 ?

jorims
Автор

Thank you so much! Help me clear my doubt!!!

yidan_wang_ittan
Автор

How do we get the cloud foundry env variables like VCAP_APPLICATION in node.js ?

abcd
Автор

I have a problem and also a question. what if I want to use multiple databases in dotenv?

dph
Автор

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.

anounTT
Автор

Klick (=like) first, then watch the content ;)))
Excellent content/topic

SaintHanappi