3.4 Hiding API Keys with Environment Variables (dotenv) and Pushing Code to GitHub

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ม.ค. 2025

ความคิดเห็น • 227

  • @Warpgatez
    @Warpgatez 2 ปีที่แล้ว +7

    After years, I still come back to your videos. Doesn't matter which one. I just come back to them. They solve so many issues. When I first discovered you I wasn't working with JS at all. But enjoyed watching your videos. Now I am working with JS. So I am back

  • @janetrajkoski1424
    @janetrajkoski1424 3 ปีที่แล้ว +7

    As someone who just started learning to code and my first interview being: "The hell you doing your API key is public", this was a godsend video. Very to the point and clear explanation. Subscribed

  • @aristotleanderson930
    @aristotleanderson930 4 ปีที่แล้ว +42

    This is a great tutorial! Thank you for being quick and to the point, as well as informative and helpful!

    • @gustavotomas5214
      @gustavotomas5214 3 ปีที่แล้ว

      You probably dont give a damn but does someone know a way to log back into an instagram account?
      I somehow forgot my account password. I love any help you can give me.

    • @casenace5722
      @casenace5722 3 ปีที่แล้ว

      @Gustavo Tomas Instablaster :)

    • @gustavotomas5214
      @gustavotomas5214 3 ปีที่แล้ว

      @Casen Ace thanks so much for your reply. I found the site thru google and Im waiting for the hacking stuff now.
      Seems to take a while so I will reply here later when my account password hopefully is recovered.

    • @gustavotomas5214
      @gustavotomas5214 3 ปีที่แล้ว

      @Casen Ace It did the trick and I finally got access to my account again. I am so happy!
      Thank you so much, you really help me out!

    • @casenace5722
      @casenace5722 3 ปีที่แล้ว

      @Gustavo Tomas no problem =)

  • @hj1916
    @hj1916 ปีที่แล้ว +3

    It was never boring! Actually, you made this serious topic so fun like magic. Also, I loved the ending credit of the train. Creative idea!!! Thank you so much!!!!

  • @simonmafanye.3537
    @simonmafanye.3537 ปีที่แล้ว

    Watched your video for 5minutes and i have no choose but to hit the Subscribe button very fast.
    I love your style of teaching,

  • @CodeBUNNY
    @CodeBUNNY 3 หลายเดือนก่อน

    it's been years and i still love your content.

  • @PROTOTYPZ
    @PROTOTYPZ 4 หลายเดือนก่อน

    Just found this guy's channel and he cooks, simple easy to understand instructions, great job to the creator! Always going to check your channel for any information I need before others.

  • @honeybcomb
    @honeybcomb 4 ปีที่แล้ว +3

    I randomly came across this video and I can't go without thank you ! Your explanations are very clear and makes the course material simple to understand. Thank you very much ! I am so happy I fond your channel today :))

  • @zeyadahmedsamer3443
    @zeyadahmedsamer3443 2 ปีที่แล้ว +2

    no words can describe your awesome explanation

  • @SaiKumar-vf9lz
    @SaiKumar-vf9lz 4 ปีที่แล้ว

    From hiding api keys to adding local source to GitHub ..well summarized things in 10 mins ..great video !

  • @moaazbhnas886
    @moaazbhnas886 4 ปีที่แล้ว +5

    I was searching for a video about env file and felt relief when I saw yours

  • @MrGreg557
    @MrGreg557 2 ปีที่แล้ว

    What a great series man, I'm grateful everyone can use resources like this. Going from knowing almost 0 JS to deploying my app was very satisfying.
    One update though: if you get this error like me: "npm ERR! Missing script: "start"", add this to the end of your package.json file, before the finishing curly brace:
    ,"scripts": {
    "start": "node index.js"
    },

  • @Rlc201
    @Rlc201 4 ปีที่แล้ว +2

    How i didn't know this channel? Awesome tutorial and one of the best teachers that i have ever seen on youtube. Keep up!

  • @zwlw
    @zwlw 2 ปีที่แล้ว +3

    you're a legend dude this is a life saver

  • @smashing_data4292
    @smashing_data4292 11 หลายเดือนก่อน

    As someone who has done this before on my own projects I can say this is legit. Immediate subscribe.

  • @aakash-codes
    @aakash-codes ปีที่แล้ว

    I just love the way you teach things! Doesn't even let me feel boring for a single sec! 😊🚀

  • @kareng9484
    @kareng9484 6 หลายเดือนก่อน

    Bro, thank you very much, this is exactly what I needed, you're so good at explaining things

  • @bandarabdullah40
    @bandarabdullah40 5 ปีที่แล้ว

    I was suffering to understand the environment variable and its benefits this video the best explanation I have ever seen.

  • @benSfft
    @benSfft 4 ปีที่แล้ว +6

    Thanks a lot ! That's clear and the objectives are so well explained ! I didn't even know that we could code on ecstasy !

  • @arshamazami159
    @arshamazami159 4 ปีที่แล้ว

    The best video about environment variable and how to use them👍👍👍

  • @SnobbyLion
    @SnobbyLion ปีที่แล้ว

    You're so good at explaining things! Thank you!

  • @snehagangurde6266
    @snehagangurde6266 4 ปีที่แล้ว +1

    Thank you so much i have been searching one good video for days. finally got this one. this one is quick, understandable

  • @kingsley3194
    @kingsley3194 3 ปีที่แล้ว +1

    Thank you so much. You saved my day with this explanation

  • @Niehde
    @Niehde 5 ปีที่แล้ว +20

    Nice video! I've just recently pushed some API keys to Github. Fortunately they have a service that lets you know when you've screwed up.

  • @leerenae313
    @leerenae313 3 ปีที่แล้ว +1

    Hey, love your videos! they're so straight to the point Thank you for putting this out for free 🙏

  • @220syedrazamehdirizvi7
    @220syedrazamehdirizvi7 7 หลายเดือนก่อน

    U made it so fun to watch ....❤

  • @tegaogheneovo5881
    @tegaogheneovo5881 3 ปีที่แล้ว

    So keep working on my project and when I want to deploy hide all my keys and db names thank you 😁

  • @kenfeier5542
    @kenfeier5542 ปีที่แล้ว

    Great tutorial, but I do want to mention one thing. Environmental variables help you hide your sensitive information for version control purposes. If you build a public website and have environmental variables showing on client side, a user can open the debugger and hover over those variables and see the values of them. Make sure that you use these variables on back-end (server) side if you don't want anyone to see their values.

  • @skrillex15
    @skrillex15 3 ปีที่แล้ว

    Thanks for this playlist. Really helped

  • @bacanalienigena
    @bacanalienigena 2 ปีที่แล้ว

    It works amazingly, thanks a million!

  • @nofacee94
    @nofacee94 5 ปีที่แล้ว +6

    If your file is called index.js, you can just do `node .` or `node index`

  • @drhastings
    @drhastings 3 ปีที่แล้ว

    Simple and straight to the point thank you👏🏿

  • @akhilyadav7426
    @akhilyadav7426 5 ปีที่แล้ว +3

    Please publish the continued episode fastly sir waiting for it
    A subscriber from INDIA
    #Codingtrain

  • @danieloliveira9815
    @danieloliveira9815 4 ปีที่แล้ว

    Typing those command line commands made me feel like a real programmer 😎 Thank you for this awesome playlist!

  • @familyjuega12345
    @familyjuega12345 3 ปีที่แล้ว

    Awesome content and explanation, thanks man!

  • @sweickel
    @sweickel 3 ปีที่แล้ว

    Thank you! This is exactly the video and explanation I needed!

  • @dennisgonzales9521
    @dennisgonzales9521 3 ปีที่แล้ว

    Very engaging! thank you for the lesson.

  • @zensic
    @zensic 2 ปีที่แล้ว

    Thank you! Was just looking for this

  • @lorisp186
    @lorisp186 2 ปีที่แล้ว

    Thank you man, I was exactly looking for that

  • @zorro1rr
    @zorro1rr 4 ปีที่แล้ว +3

    I'm getting the api key returned in my terminal, but now my data is not being returned in the browser and getting console error: Uncaught ReferenceError: require is not defined. Help please

    • @TheCodingTrain
      @TheCodingTrain  4 ปีที่แล้ว

      Our Coding Train Discord is a great place to get help with coding questions ! discord.gg/hPuGy2g
      - The Coding Train Team

  • @edwincaceresi.3284
    @edwincaceresi.3284 3 ปีที่แล้ว +1

    Thanks! It was very clear!

  • @ncpurge789
    @ncpurge789 4 ปีที่แล้ว

    THIS SAVED MY LIFE THANK YOU

  • @oyetorostephen5010
    @oyetorostephen5010 5 ปีที่แล้ว +2

    THank you! I find this fun to learn

  • @ousmaneyadely
    @ousmaneyadely 5 ปีที่แล้ว

    Thanks a lot! I was totally stuck with a bug until I watched your video. So clarifying!

  • @noco2605
    @noco2605 2 ปีที่แล้ว

    Thank you very much for your explanation 😊

  • @pjguitar15
    @pjguitar15 3 ปีที่แล้ว +1

    You're a great teacher!!!

  • @sharadsharma3176
    @sharadsharma3176 5 ปีที่แล้ว

    eagerly waiting for the next video of this series....
    I want to know more about the available hosting services for node.

  • @hargur4121
    @hargur4121 2 ปีที่แล้ว

    Thanks a lot! This has been a lifesaver

  • @JanacMeena
    @JanacMeena 2 ปีที่แล้ว

    2:00 start
    5:30 Create a sample .env
    Make sure .gitignore has .env listed

  • @DieHard88913
    @DieHard88913 4 ปีที่แล้ว

    Thank you! this helped me a lot, earned a new sub :D

  • @ivankljun2542
    @ivankljun2542 4 ปีที่แล้ว

    Very nice, thank you, very educational and entertaining! :)

  • @appiahseth5319
    @appiahseth5319 4 ปีที่แล้ว

    Great presentation. Thank you very much

  • @akramsyed3628
    @akramsyed3628 2 ปีที่แล้ว

    i am first here and very impresed they way you teach , ke

  • @DigitalMonsters
    @DigitalMonsters 5 ปีที่แล้ว +8

    Whats the difference between using dotenv and just throwing them in another javascript file that you export from and then adding that file to the gitignore?
    I could watch the video and most likely get the answer to that question; but in the interest of being one of the earliest comments.... please understand.

    • @ridespirals
      @ridespirals 5 ปีที่แล้ว

      kind of the same thing, but environment variables are more common because you can configure them more easily on other host services like heroku, CI systems like Jenkins, you can change then on a command line, lots of other ways.

    • @BertMaurau
      @BertMaurau 5 ปีที่แล้ว

      Waiting for the actual answer, but like for me, my main reason for using .env files is because it's a "standard" and you can share that file between different languages for example. A single .env file can be read in NodeJS, PHP, Python,... (others?) without changing any syntax and let dotenv handle everything. My second reason would be the "environment" part. It's clear that it is environment-based and the scope for these variables is globally accessible (less an issue in NodeJS probably) within classes, methods, ..

    • @johncerpa3782
      @johncerpa3782 5 ปีที่แล้ว

      Ahh true that

    • @Loppy2345
      @Loppy2345 5 ปีที่แล้ว +1

      For the same reason you wouldn't take a helicopter to do your grocery shopping, it's not the right tool for the job.

  • @bluemagicuk
    @bluemagicuk 5 ปีที่แล้ว +1

    super helpful - thank you!

  • @nighknight9012
    @nighknight9012 4 ปีที่แล้ว

    if you are working on linux you may experience a problem when running the code, "undefined" gets returned, thats because you need to set the env variable yourself.
    go to bashrc and do export ENV_VARIABLE=VALUE no spaces around the equal and if the VALUE has spaces add quotes around it

  • @santra528
    @santra528 4 ปีที่แล้ว +1

    Using dotenv package and store the API_KEY in .env file does not completely hide the API_KEY. It is fine for GitHub because someone visiting this repo they wont be able to see the API_KEY. But if the project is deployed in sever then anyone can see the API_KEY from the browser when they visit this particular website. The best way to hide the API_KEY is store it in the backend and make the API calls from the backend only. Only send the response data to the frontend. And to add more security you can set up CORS for the API_KEY so even if someone gets access to the API_KEY they wont be able to send request as the request will be rejected and only the request from the domains mention in the CORS will be able to make successful request using this API_KEY.

    • @incandescentbruh
      @incandescentbruh 3 ปีที่แล้ว

      No one is dumb enough to put the api key in frontend, also the example code in the video is using express js which is run by node js in backend.

  • @santiagootero3580
    @santiagootero3580 9 หลายเดือนก่อน

    you are the goat, thanks so much

  • @Symparanekromenoii
    @Symparanekromenoii 4 ปีที่แล้ว

    So, so useful. Thanks!

  • @abigiyatadesse2672
    @abigiyatadesse2672 2 ปีที่แล้ว

    Thanks so much this is helpful.

  • @coffeymay6775
    @coffeymay6775 4 ปีที่แล้ว +1

    It says require is not defined for me in the console. I followed the steps in terminal, have the lastest version of node etc.???

  • @techmarinar
    @techmarinar 3 ปีที่แล้ว

    thanx man , this was helpful

  • @mohammedraqeeb4392
    @mohammedraqeeb4392 3 ปีที่แล้ว

    Great explanation

  • @nicetomeetugaming7024
    @nicetomeetugaming7024 2 ปีที่แล้ว

    Amazing video sir!

  • @adedimolao9094
    @adedimolao9094 4 ปีที่แล้ว +2

    can you use .env and gitignore in a vanilla js project?

  • @nicetomeetugaming7024
    @nicetomeetugaming7024 2 ปีที่แล้ว

    BTW you are amazing teacher!

  • @LimitlessGamingYoutubeChannel
    @LimitlessGamingYoutubeChannel 3 ปีที่แล้ว

    Super helpful video!

  • @dreznik
    @dreznik 5 ปีที่แล้ว +1

    sheefmahn brilliant series of videos. any videos where you interact with a Database-as-a-Service? SQL or not

  • @serdarinjo
    @serdarinjo 2 ปีที่แล้ว

    Muchas gracias bro 😀!

  • @Vincetroid
    @Vincetroid 4 ปีที่แล้ว

    You saved me, suscribed!

  • @aham3687
    @aham3687 5 ปีที่แล้ว

    could continue this series with PWA. This has been popular with web technology in this modern day.

  • @devinschlegel1763
    @devinschlegel1763 5 ปีที่แล้ว +10

    his next coding challenge should be solving the heat equation based off of 3blue1brown's video on the same topic

    • @TheCodingTrain
      @TheCodingTrain  5 ปีที่แล้ว

      Please suggest here! github.com/CodingTrain/Rainbow-Topics/issues

  • @michaelamay9714
    @michaelamay9714 4 ปีที่แล้ว +1

    require('dotenv').config is a sever-side technology not a browser, hence, I am getting an error on my console. How are you not getting this error?

  • @GopalChand
    @GopalChand ปีที่แล้ว

    Hi, how about if i am using Docker and dont want to publish my .env file in git. But my application is require env file. Can you pls help how to use .env file in Docker container or K8

  • @xtree2817
    @xtree2817 2 ปีที่แล้ว

    I exactly landed where i wanted to be. I was just looking for this

  • @ilearncode7365
    @ilearncode7365 2 ปีที่แล้ว

    From a “security/ privacy” standpoint, how is this any better than just having a js file with a variable for thr api key in it?

  • @RayfranRocha
    @RayfranRocha 4 ปีที่แล้ว +1

    Spectacular tutorial! Thank you. It's very clear. I wonder if using any browser inspector, can anyone see the API_KEY? Looking inside the code or in the Request to the API message?

  • @kritikshivanshu
    @kritikshivanshu 4 ปีที่แล้ว

    @TheCodingTrain Hi there! I am facing problem in order to upload .env file in my github repo. Since the application doesn't fetching information. What to do???Please help me.

  • @weixiangng8279
    @weixiangng8279 5 หลายเดือนก่อน

    If I were to deploy to vercel how can I retrieve the .env values?

  • @m_ko
    @m_ko 5 ปีที่แล้ว

    So nice thanks for this video

  • @carlosduque8767
    @carlosduque8767 3 ปีที่แล้ว

    Why when you put the node_modules in the .gitignore file you put a / in front of it?

    • @dusanlukic6784
      @dusanlukic6784 2 ปีที่แล้ว

      because node modules is a folder and then git will ignore every file in that folder

  • @MuhammadRizky-ub3oy
    @MuhammadRizky-ub3oy 2 ปีที่แล้ว

    i love your energy

  • @patrickporter6441
    @patrickporter6441 4 ปีที่แล้ว

    I had a question: Can the same effect be accomplished with a config.json and including that in the gitignore?

  • @Cam-lm6wo
    @Cam-lm6wo 3 ปีที่แล้ว +1

    incredible video, I spend like 1 year in a College trying to use GitHub as they told me without actually know what I was doing. thank you! Just a question... Can I add to the .env file a private key from firebase?

  • @abhishektyagi4428
    @abhishektyagi4428 5 ปีที่แล้ว +1

    Sir Could you please make a video explaining the resources you use to learn or enhance your programming skills

  • @catalinhora6489
    @catalinhora6489 3 ปีที่แล้ว

    i'm working with custom-env pretty similar, but I need to have two env files, for two environments, how should this be treated? How can i make it work?

  • @sazaam
    @sazaam 4 ปีที่แล้ว

    Simply awesome

  • @Viralplace
    @Viralplace 4 ปีที่แล้ว

    but this works just for development on github... if I go in production like a jam stack project? it is not hidden right?

  • @GabrielTobing
    @GabrielTobing หลายเดือนก่อน

    Here after learning developers added the api key and people were able to view it in the git history commit before it was published XD

  • @bhavsar9904
    @bhavsar9904 3 ปีที่แล้ว

    Hello I am using Angular latest version with nodejs and I am new to it. In Angular we have environment.ts file where we keep API key details. I have used dotenv and generating environment.ts with with node script using dotenv. Now when we build and serve angular application and go to browser and do page view source. Enviornment.ts file is viewable in main.js file with all the details and that I dont want to expose. Any suggestion how to stop exposing this file data in page view source?

  • @Jb67912
    @Jb67912 4 ปีที่แล้ว

    you don't need an access token for the logs js file? It seems the website of mapbox requires one

  • @unscripted483
    @unscripted483 4 ปีที่แล้ว

    so if someone down loads the repository to try out the web app will they still be able to use is even though they wont have the api key... (for me i didn't want to show the world my database URL and password)

  • @gideonaswani2449
    @gideonaswani2449 2 ปีที่แล้ว

    Awesome, thanks

  • @ashy7198
    @ashy7198 2 ปีที่แล้ว

    are .env not rendered to the browser then or something? What is to stop someone from viewing the app in their browser and fetching your API key out of the rendered JS with inspect element?

    • @TheCodingTrain
      @TheCodingTrain  2 ปีที่แล้ว +1

      That is correct! The way I've set up this project the .env files are hidden on the server. You can only see them if you have login access to the server where they are held.

    • @BrianKiddDevDesign
      @BrianKiddDevDesign 2 ปีที่แล้ว

      @@TheCodingTrain Excellent. This was a very fun and informative series. Thanks.

  • @alejandrocano88
    @alejandrocano88 4 ปีที่แล้ว

    I have a react with typescript project and the console.log(process.env) works just fine without intalling 'dotnet' , perhaps this function is already implemented?

    • @nickspringer5755
      @nickspringer5755 4 ปีที่แล้ว

      Theres a SOLID chance dotenv is a dependency of CRA

    • @alejandrocano88
      @alejandrocano88 4 ปีที่แล้ว

      @@nickspringer5755
      here's all my dependencies
      "@material-ui/core": "^4.9.8",
      "@material-ui/icons": "^4.9.1",
      "@material-ui/lab": "^4.0.0-alpha.47",
      "@testing-library/jest-dom": "^4.2.4",
      "@testing-library/react": "^9.3.2",
      "@testing-library/user-event": "^7.1.2",
      "@types/classnames": "^2.2.10",
      "@types/jest": "^24.0.0",
      "@types/lodash.orderby": "^4.6.6",
      "@types/node": "^12.0.0",
      "@types/react": "^16.9.0",
      "@types/react-dom": "^16.9.0",
      "@types/react-input-mask": "^2.0.5",
      "@types/react-redux": "^7.1.7",
      "@types/react-router-dom": "^5.1.3",
      "@types/react-table": "^7.0.16",
      "@types/recompose": "^0.30.7",
      "@types/redux-actions": "^2.6.1",
      "@types/yup": "^0.26.34",
      "axios": "^0.19.2",
      "classnames": "^2.2.6",
      "clsx": "^1.1.0",
      "date-fns": "^2.12.0",
      "formik": "^2.1.4",
      "lodash.isequal": "^4.5.0",
      "lodash.orderby": "^4.6.0",
      "react": "^16.13.1",
      "react-date-range": "^1.0.3",
      "react-day-picker": "^7.4.8",
      "react-dom": "^16.13.1",
      "react-input-mask": "^2.0.4",
      "react-intl": "^4.5.3",
      "react-redux": "^7.2.0",
      "react-router-dom": "^5.1.2",
      "react-scripts": "3.4.1",
      "react-spring": "^8.0.27",
      "react-table": "^7.0.4",
      "react-thunk": "^1.0.0",
      "react-transition-group": "^4.3.0",
      "react-use-measure": "^2.0.0",
      "recompose": "^0.30.0",
      "redux": "^4.0.5",
      "redux-actions": "^2.6.5",
      "redux-persist": "^6.0.0",
      "redux-persist-transform-filter": "^0.0.20",
      "redux-saga": "^1.1.3",
      "reselect": "^4.0.0",
      "rsuite": "^4.5.0",
      "sweetalert2": "^9.10.12",
      "typescript": "^3.8.3",
      "use-react-router": "^1.0.7",
      "yup": "^0.28.3"

  • @cperez7785
    @cperez7785 3 ปีที่แล้ว

    Does anyone know how to find your API key? The text folder I created I accidentally deleted and I had to re-generate new APY keys but I do not know where I may find this text file to update it. Any help will appreciate it!

  • @pierosabino
    @pierosabino 4 ปีที่แล้ว

    Hi, I followed your video to publish code on github using dotenv but it doesn't work

  • @Philson
    @Philson 2 ปีที่แล้ว +1

    Is it secure deploying it tho

  • @WEBB99
    @WEBB99 5 ปีที่แล้ว +1

    how is this different from just making a json file and storing it there?

    • @TheCodingTrain
      @TheCodingTrain  5 ปีที่แล้ว +1

      Ultimately it's the same, but a lot of web hosting services support environment variables in native ways, see my last video in this series!

  • @lilynn7777
    @lilynn7777 10 หลายเดือนก่อน

    Great Tutorial! Although i have a question and i hope some good soul will answer me.
    During my Bootcamp, we never got tought or warned to hide our API Keys. So now that i am about to apply for jobs, i have been overwhelmed with the fact that i need to hide my personal API key that i used for my projects (it's a free personal key from my bootcamp). So my question is: What should i do that i already committed and publicly pushed all of my projects and API keys on my github? Thankfully no one has access to it yet but i need to take action before sending applications or post my github to Linkedin. Any advice would be greatly appreciated 🙏🙏