Using dotenv with NodeJS and Environment Variables

Поділитися
Вставка
  • Опубліковано 4 лют 2025

КОМЕНТАРІ • 94

  • @TjSpoonManJacques
    @TjSpoonManJacques 3 роки тому +3

    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
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому +1

      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! 😀

    • @TjSpoonManJacques
      @TjSpoonManJacques 3 роки тому

      @@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

  • @patrickkornetzke3889
    @patrickkornetzke3889 4 роки тому +5

    Yet another helpful, clear tutorial. Thank you so much for your videos!

  • @KyrylPetruk
    @KyrylPetruk 4 роки тому +1

    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.

  • @ararune3734
    @ararune3734 2 роки тому

    Concise, well structured, clear and a pleasant voice, thanks man

  • @appleforth
    @appleforth 4 роки тому +5

    Hey mate, thanks so much for this! Have been looking for a clear explanation on this package for a while

  • @colindante5164
    @colindante5164 Рік тому

    Thankyou much. As always your methods of explaining are top notch. ))

  • @kurtwillrich7795
    @kurtwillrich7795 3 роки тому

    Thanks for the great video - I read several other tutorials, but didn't really get it until I saw this. Thanks!

  • @guillegt7983
    @guillegt7983 3 роки тому +2

    Hi Steve! Excellent tutorial. Congratulations. A really good job. Thank you very much for sharing your knowledge.

  • @karma_yogi_42
    @karma_yogi_42 4 роки тому +1

    presented in a very clear understandable way

  • @vinodmathew85
    @vinodmathew85 4 роки тому +1

    Excellent explanation, crisp and clear.

  • @deepdivedevs100
    @deepdivedevs100 4 роки тому +2

    that is some serious typing speed even thought i watched in 1.25 😂 , you are a pro

  • @raamch
    @raamch 3 роки тому +2

    Cool stuff, explained very well. Thank you so much.

  • @aaronargottelopez3488
    @aaronargottelopez3488 2 роки тому

    This was excellent. You helped me a lot with your excellent video. I am thankful to you.

  • @RD-jr8nv
    @RD-jr8nv 4 роки тому

    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.

  • @fricktion184
    @fricktion184 2 роки тому

    Wonderful Tutorial man! Thanks a bunch!

  • @elwyn02
    @elwyn02 3 роки тому

    Subscribed ! Thank You! ❤️

  • @Pareshbpatel
    @Pareshbpatel 3 роки тому

    Excellent Tutorial on environment variables using dotenv. Thanks.
    {2021-08-03}

  • @5ystemNoveary
    @5ystemNoveary 5 років тому

    I've been looking for this tutorial. Thanks sir

  • @CastleShield
    @CastleShield 2 роки тому

    To the point, as always. Thanks a lot, mate.

  • @tmstest9688
    @tmstest9688 4 роки тому

    Nice clean demo. Thanks, bro

  • @amankhanna354
    @amankhanna354 3 роки тому

    Thanks for this brother🔥✊

  • @retrofutur1st
    @retrofutur1st 3 роки тому

    Liked and subscribed! Excellent vid

  • @milankbudha
    @milankbudha 3 роки тому

    thank u so much..it was really helpful

  • @pryansh_
    @pryansh_ 2 роки тому +1

    it was helpful, thanks

  • @alexandryurkov9168
    @alexandryurkov9168 3 роки тому

    Man, u help me a lot. Thank you

  • @mareczek1239
    @mareczek1239 3 роки тому

    finally, I found what I need, thx

  • @whatsmyname9742
    @whatsmyname9742 3 роки тому +2

    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?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому +1

      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

    • @whatsmyname9742
      @whatsmyname9742 3 роки тому +1

      @@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.

  • @michaelbussert4291
    @michaelbussert4291 3 роки тому

    Thanks for doing a video on this!

  • @rizaldyrequiero5643
    @rizaldyrequiero5643 5 років тому

    I will use it in my express apps, you have my very thanks

  • @MrBowmanMakes
    @MrBowmanMakes 4 роки тому

    great flow and demonstration, thanks!

  • @austinjohn8713
    @austinjohn8713 3 роки тому

    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.

  • @michaelcarnevale5620
    @michaelcarnevale5620 3 роки тому

    quick and easy and useful thanks

  • @lennythobejane742
    @lennythobejane742 3 роки тому

    Thanks a lot, that was really helpful

  • @russelldriver6394
    @russelldriver6394 3 роки тому

    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?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому

      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

    • @russelldriver6394
      @russelldriver6394 3 роки тому +1

      @@SteveGriffith-Prof3ssorSt3v3 Great thank you Mr Griffith!

  • @logicawe
    @logicawe 5 років тому

    Looks good, that's for the quality content

  • @quaternion-pi
    @quaternion-pi 5 років тому

    Really, very helpful. Thanks.

  • @stefanafairman6889
    @stefanafairman6889 4 роки тому

    Super helpful, thank you!

  • @growingisgood
    @growingisgood 3 роки тому

    This is great ! Question: How do I organise the file so that different variables are provided depending on whether in development or build mode ?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому +1

      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

    • @growingisgood
      @growingisgood 3 роки тому

      Thank you so much !

    • @austinjohn8713
      @austinjohn8713 3 роки тому

      @@SteveGriffith-Prof3ssorSt3v3 that deserves its own video

  • @olaifatimothy4173
    @olaifatimothy4173 3 роки тому

    Thank you for doing this

  • @prabujs1785
    @prabujs1785 2 роки тому

    i want to create multiple .env files for multiple environments. how to do that ?

  • @bonchan4404
    @bonchan4404 3 роки тому

    subscribed ! thank you !

  • @abhishekjawanpuria4019
    @abhishekjawanpuria4019 3 роки тому

    Is there any way to access those environment variables directly through browser side javascript?

  • @murat7456
    @murat7456 3 роки тому

    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.

  • @navcarlos6086
    @navcarlos6086 3 роки тому

    may I know how secure are the environment variables? I feel like hackers can look at them during runtime

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому

      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

  • @gowthambhat1498
    @gowthambhat1498 4 роки тому +1

    Man!! You Rock

  • @carter8679
    @carter8679 4 роки тому

    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
      @SteveGriffith-Prof3ssorSt3v3  4 роки тому

      dotenv is a node module for accessing and creating environment variables when launching your Node app. It's not connected to git.

    • @carter8679
      @carter8679 4 роки тому

      @@SteveGriffith-Prof3ssorSt3v3 ok so it's not specifically a tool for keeping confidential info off of the internet... back to stack exchange... thanks!

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 роки тому +1

      @@carter8679 environment variables are for hiding secret info.
      .gitignore files are for keeping info out of a repo

  • @asadalisoomro8937
    @asadalisoomro8937 2 роки тому

    helpful! Thank you

  • @nicetomeetugaming7024
    @nicetomeetugaming7024 2 роки тому

    Good video!

  • @LGseeker
    @LGseeker 4 роки тому

    great video, I almost pushed a public repo on github with my mongo db creds lol

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 роки тому

      Yikes! Good thing you caught it.
      Although, the guys at Starbucks did just that a couple years ago. So, don't feel too bad.

  • @JanacMeena
    @JanacMeena 2 роки тому

    How do I setup production env files and dev?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому +1

      Usually by having a different .env file in your production and your dev environments

    • @JanacMeena
      @JanacMeena 2 роки тому

      @@SteveGriffith-Prof3ssorSt3v3 thx Steve, and how should we version and sync these env files if not via vcs?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому

      @@JanacMeena manually. Do not include them in source control

  • @vinodkumarp7577
    @vinodkumarp7577 4 роки тому

    Hello
    Steve ,
    helpful .
    What if we want to maintain two different files for production and development .
    please help with that .

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 роки тому

      Please add that as another tutorial request in the comments here - ua-cam.com/video/LCezax2uN3c/v-deo.html

  • @beratdinckan5585
    @beratdinckan5585 3 роки тому

    thanks for the video

  • @aaronargottelopez3488
    @aaronargottelopez3488 2 роки тому

    ¡Gracias, crack!

  • @Theo_Phage
    @Theo_Phage 3 роки тому

    What about how to use it multiple environments?

  • @anurag9110
    @anurag9110 3 роки тому

    How to load config values based on NODE_ENV?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому

      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

  • @soltiscd
    @soltiscd 5 років тому

    Can I access this in the console using console.log(port)?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  5 років тому

      yes! - assuming you are talking about the console on the server in VSCode, not in the browser.

    • @soltiscd
      @soltiscd 5 років тому +1

      @@SteveGriffith-Prof3ssorSt3v3 I was referring to the dev console but that answers my question. Thanks!

  • @nabeeljaved1742
    @nabeeljaved1742 4 роки тому

    thanks it was helpful

  • @yadusolparterre
    @yadusolparterre 3 роки тому

    Great video! But isn't dotenv a dev dependency?

  • @tannermartz6761
    @tannermartz6761 3 роки тому

    i have been trying to solve this 5 min vid all day and i cannot figure out my error. require doesnt work! help please :(

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому

      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

    • @carolinatronci1654
      @carolinatronci1654 2 роки тому

      have the same problem,did you solve?

  • @calarcher4869
    @calarcher4869 2 роки тому

    THANK YOU

  • @islomumar1049
    @islomumar1049 4 роки тому

    thank you

  • @higgsboson3900
    @higgsboson3900 2 роки тому

    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.

  • @MrBader662
    @MrBader662 3 роки тому

    thank you