I gave you a major shout-out on both of my channels (how JavaScript change my life) as the one person who helped me understand EVERYTHING! Thank you for using your life to help a 49 year old dude in New Orleans who struggled with self-enhancement and reinvention. Brother, I owe you a pot of gumbo.
@@SteveGriffith-Prof3ssorSt3v3 LOL come on down - we got you!!! Here's a link to the my testimonial of your amazing body of work! Thank you ua-cam.com/video/IPVFuzuO2h0/v-deo.html
Hi, I have been looking through dozens of tutorial from different channels on the same topic. This video I've liked on the 3rd second. You have a very pleasant voice. Oh, the video is informative as well. Thank you.
Hi, Steve another greater tutorial. I had a query about how can I select values of env variables depending on the server. For Eg if I run the app in development the app should select PORT 3000 but in prod, it should set PORT 500?
You just need to have an if statement that checks the value of your production/development mode environment variable. Then set the port with a different number. OR you can set a different value for PORT in the scripts in package.json. Have different script calls for each mode - production and development. Pass in the value as an environment variable and read it from process.env instead of using the dotenv npm package. ua-cam.com/video/-SaZiADGLHs/v-deo.html ua-cam.com/video/UvgtQ8JZ9jw/v-deo.html
@@SteveGriffith-Prof3ssorSt3v3 Hi Steve, Thanks for explaining. Already saw those 2 videos, those were of great help too. I think 'if else' approach is good one as there can be a lot of env variables. I also saw 'env-cmd' npm package which is also great, one can setup different env variables as objects and load it while running a script.
how do you separate the environment variables for development and production. this is an issue that hardly any tutorial addresses in a way that sinks in.
If you are setting up a bunch of API keys that will be needed in production, then how would you get your .env file to your remote server if it is in the gitignore file? After a quick search I read you should setup a .env file manually on your remote server with all the same variables you need. Would that be best practise ? Is this not just duplication?
You need to guard your API keys carefully. You can manually upload a file with the keys to the server or even just set the keys as env variables from the server command line. Dont keep them in your git repo
Node has an environment variable called NODE_ENV that is 'development' by default but can be set to 'production'. Then use an if statement to look at the value and call the config( ) method to load a different file. let dotenv = require('dotenv'); if (process.env.NODE_ENV === "development") { dotenv.config({}) }else{ dotenv.config({}) } nodejs.dev/learn/nodejs-the-difference-between-development-and-production
despite the fact that you did everything in the video correctly, if your .env value is undefined; you can try to move the .env file to the root folder.
They are on the server and only accessible to the code. They are not written down anywhere. A hacker could see them if they got command line access to your server, not during code run unless you were logging them to the console
wait so if I 'git init' it looks like I have to manually .gitignore the .env file... git doesn't automatically ignore it. what's the difference then between using dotenv and just creating some other generic config file and .gitignoring that?
@@SteveGriffith-Prof3ssorSt3v3 ok so it's not specifically a tool for keeping confidential info off of the internet... back to stack exchange... thanks!
ENV variables are created before your script runs so the values should exist in the environment regardless of whether you are in development or production mode. vanilla NodeJS lets you access the values of any ENV variable through process.env nodejs.org/docs/latest/api/process.html#process_process_env
require is a core part of NodeJS. If you are having trouble with it then you are passing in an invalid path or are missing the extra ( ) after it to run a returned function (depends on what you are importing). ua-cam.com/video/pP4kjXykbio/v-deo.html
I gave you a major shout-out on both of my channels (how JavaScript change my life) as the one person who helped me understand EVERYTHING! Thank you for using your life to help a 49 year old dude in New Orleans who struggled with self-enhancement and reinvention. Brother, I owe you a pot of gumbo.
Thank you so much for your comment. That's why I do this.
If I ever make it down to Louisiana I will definitely collect! 😀
@@SteveGriffith-Prof3ssorSt3v3 LOL come on down - we got you!!! Here's a link to the my testimonial of your amazing body of work! Thank you ua-cam.com/video/IPVFuzuO2h0/v-deo.html
Yet another helpful, clear tutorial. Thank you so much for your videos!
Hi, I have been looking through dozens of tutorial from different channels on the same topic.
This video I've liked on the 3rd second.
You have a very pleasant voice.
Oh, the video is informative as well.
Thank you.
Concise, well structured, clear and a pleasant voice, thanks man
Hey mate, thanks so much for this! Have been looking for a clear explanation on this package for a while
Thankyou much. As always your methods of explaining are top notch. ))
Thanks for the great video - I read several other tutorials, but didn't really get it until I saw this. Thanks!
Hi Steve! Excellent tutorial. Congratulations. A really good job. Thank you very much for sharing your knowledge.
presented in a very clear understandable way
Excellent explanation, crisp and clear.
that is some serious typing speed even thought i watched in 1.25 😂 , you are a pro
Cool stuff, explained very well. Thank you so much.
This was excellent. You helped me a lot with your excellent video. I am thankful to you.
Thankyou for this, great content. You have a great voice for this, if the people don't subscribe from the content, they'll subscribe from seduction.
Wonderful Tutorial man! Thanks a bunch!
Subscribed ! Thank You! ❤️
Excellent Tutorial on environment variables using dotenv. Thanks.
{2021-08-03}
I've been looking for this tutorial. Thanks sir
To the point, as always. Thanks a lot, mate.
Nice clean demo. Thanks, bro
Thanks for this brother🔥✊
Liked and subscribed! Excellent vid
thank u so much..it was really helpful
it was helpful, thanks
Man, u help me a lot. Thank you
finally, I found what I need, thx
Hi, Steve another greater tutorial. I had a query about how can I select values of env variables depending on the server. For Eg if I run the app in development the app should select PORT 3000 but in prod, it should set PORT 500?
You just need to have an if statement that checks the value of your production/development mode environment variable. Then set the port with a different number.
OR
you can set a different value for PORT in the scripts in package.json. Have different script calls for each mode - production and development. Pass in the value as an environment variable and read it from process.env instead of using the dotenv npm package.
ua-cam.com/video/-SaZiADGLHs/v-deo.html
ua-cam.com/video/UvgtQ8JZ9jw/v-deo.html
@@SteveGriffith-Prof3ssorSt3v3 Hi Steve, Thanks for explaining. Already saw those 2 videos, those were of great help too. I think 'if else' approach is good one as there can be a lot of env variables. I also saw 'env-cmd' npm package which is also great, one can setup different env variables as objects and load it while running a script.
Thanks for doing a video on this!
I will use it in my express apps, you have my very thanks
great flow and demonstration, thanks!
how do you separate the environment variables for development and production. this is an issue that hardly any tutorial addresses in a way that sinks in.
quick and easy and useful thanks
Thanks a lot, that was really helpful
If you are setting up a bunch of API keys that will be needed in production, then how would you get your .env file to your remote server if it is in the gitignore file? After a quick search I read you should setup a .env file manually on your remote server with all the same variables you need. Would that be best practise ? Is this not just duplication?
You need to guard your API keys carefully. You can manually upload a file with the keys to the server or even just set the keys as env variables from the server command line. Dont keep them in your git repo
@@SteveGriffith-Prof3ssorSt3v3 Great thank you Mr Griffith!
Looks good, that's for the quality content
Really, very helpful. Thanks.
Super helpful, thank you!
This is great ! Question: How do I organise the file so that different variables are provided depending on whether in development or build mode ?
Node has an environment variable called NODE_ENV that is 'development' by default but can be set to 'production'.
Then use an if statement to look at the value and call the config( ) method to load a different file.
let dotenv = require('dotenv');
if (process.env.NODE_ENV === "development") {
dotenv.config({})
}else{
dotenv.config({})
}
nodejs.dev/learn/nodejs-the-difference-between-development-and-production
Thank you so much !
@@SteveGriffith-Prof3ssorSt3v3 that deserves its own video
Thank you for doing this
i want to create multiple .env files for multiple environments. how to do that ?
subscribed ! thank you !
Is there any way to access those environment variables directly through browser side javascript?
Not unless you are sending them intentionally as part of the http response
despite the fact that you did everything in the video correctly, if your .env value is undefined; you can try to move the .env file to the root folder.
may I know how secure are the environment variables? I feel like hackers can look at them during runtime
They are on the server and only accessible to the code. They are not written down anywhere. A hacker could see them if they got command line access to your server, not during code run unless you were logging them to the console
Man!! You Rock
wait so if I 'git init' it looks like I have to manually .gitignore the .env file... git doesn't automatically ignore it. what's the difference then between using dotenv and just creating some other generic config file and .gitignoring that?
dotenv is a node module for accessing and creating environment variables when launching your Node app. It's not connected to git.
@@SteveGriffith-Prof3ssorSt3v3 ok so it's not specifically a tool for keeping confidential info off of the internet... back to stack exchange... thanks!
@@carter8679 environment variables are for hiding secret info.
.gitignore files are for keeping info out of a repo
helpful! Thank you
Good video!
great video, I almost pushed a public repo on github with my mongo db creds lol
Yikes! Good thing you caught it.
Although, the guys at Starbucks did just that a couple years ago. So, don't feel too bad.
How do I setup production env files and dev?
Usually by having a different .env file in your production and your dev environments
@@SteveGriffith-Prof3ssorSt3v3 thx Steve, and how should we version and sync these env files if not via vcs?
@@JanacMeena manually. Do not include them in source control
Hello
Steve ,
helpful .
What if we want to maintain two different files for production and development .
please help with that .
Please add that as another tutorial request in the comments here - ua-cam.com/video/LCezax2uN3c/v-deo.html
thanks for the video
¡Gracias, crack!
What about how to use it multiple environments?
Different .env file in each environment.
How to load config values based on NODE_ENV?
ENV variables are created before your script runs so the values should exist in the environment regardless of whether you are in development or production mode.
vanilla NodeJS lets you access the values of any ENV variable through process.env
nodejs.org/docs/latest/api/process.html#process_process_env
Can I access this in the console using console.log(port)?
yes! - assuming you are talking about the console on the server in VSCode, not in the browser.
@@SteveGriffith-Prof3ssorSt3v3 I was referring to the dev console but that answers my question. Thanks!
thanks it was helpful
Great video! But isn't dotenv a dev dependency?
Only if you are not using it in the production environment for your env settings.
i have been trying to solve this 5 min vid all day and i cannot figure out my error. require doesnt work! help please :(
require is a core part of NodeJS. If you are having trouble with it then you are passing in an invalid path or are missing the extra ( ) after it to run a returned function (depends on what you are importing).
ua-cam.com/video/pP4kjXykbio/v-deo.html
have the same problem,did you solve?
THANK YOU
thank you
why you don't go the documentation page and tell how to use , you just pretend that you learn everything and saying everybody to learn the snippet.
thank you