You DON'T NEED Dotenv to Handle Environment Variables in Node.js Anymore!

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 พ.ย. 2024

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

  • @FireGames25
    @FireGames25 ปีที่แล้ว +19

    No need for nodemon, no need for dotenv... keeps getting better >:D

    • @0x007A
      @0x007A ปีที่แล้ว +4

      I learned about node --watch last week when I was looking for an alternative to nodemon.

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

      ​@@0x007Areally? oh my... is it better in all ways than nodemon?

    • @AnassSanba-f5d
      @AnassSanba-f5d ปีที่แล้ว

      not really lol , that's just small changes nothing impressive

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

      oh.. really? nice!. can you pls help to share that video or reference link. thanks

  • @michaelxaviercanonizado7931
    @michaelxaviercanonizado7931 5 หลายเดือนก่อน +1

    Thanks really helped! It also works with tsx when running a typescript file as a script in NextJS. Just add the same command: "tsx --env-file .env.local ${file path}"

  • @PeterVatler-hv6nf
    @PeterVatler-hv6nf 10 หลายเดือนก่อน

    Thank you for the tip! I used NVM but it always messed up the packages when I wanted to update the versions. I started using scoop package manager which is awesome, you can use as many node version as you want, it handles their packages very well, it's really easy to update the versions. At work I use 18, 20 LTS and the latest 21. I ended up installing other developer tools like Git by scoop because it's much more easier to update than using a windows installer.

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

    Still surprises me that this was not in Node since v1, but still, good to finally have it.
    Kinda wondering why the default behaviour isn't to pick up .env & the flag is only required if you want to using another filename.. i.e that is what dotenv has been doing all these years (though, I actually prefer env-var package, mostly)

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

    This is great thanks! Question I don’t use .env file locally, I add whatever variable I need in windows environment variables (for security reasons, don’t want to commit api keys or whatever by mistake) and simply call them in my apps using dotenv (process.env.someVariable). Is there a way to access these with some other flag such as the one you showed -env-file .env ? Thanks again for video

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

    A question: This works from command line (and thus in CI) but if I want to run a piece of code (say tests) from an IDE (such as VSCode), what would be required to load the env variables?

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

    vary help full video now i am using like that in package.json file
    "scripts": {
    "start": " nodemon --env-file .env ./index.js"
    },
    any more way to do this then replay me any one 🙋‍♂🙋‍♂

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

      You dont need nodemon. Node has watch feature now

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

    If you are using ts, you would use ts-node. But I don't think ts-node support --watch or --watch-path

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

    I have a question. Looking at the folder structure, the .env is inside the the src folder with index.js. When you using the terminal to load the dotevn, is it absolute to write the file that needs the environment variables it in each case ? Or is something to be loaded once and the whole app starts using it ?

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

    Thanks James for this tip 👍🏻👍🏻

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

    Still going to stick onto dotenv unless env files can be mentioned in package.json to load envs

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

    Thank you very useful also the nvm part as I was struggling between my node version with yarn it was always selecting the last one which I didn’t want. Thank you very good features 👍

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

    That cursor flashing animation is wild

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

    not sure how can the production code will read the environment

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

      What do you mean?

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

      @@JamesQQuick I deploy my code at Azure web apps, and I declare my environment variables in the web app, I don't upload any .env file just the dotenv package read the environments automatically. I am not sure whether it will work there or not

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

      @@JamesQQuick I checked everything and now I just want to clear out that I didn't know that I don't need dotenv package if I already setup the environments variables on the cloud, so yeah now I can use what you told in the video easily. Thanks

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

      Yeah so your hosting provider should take care of environment variables when it's deployed. No need to send a .env file along!@@surendramaran

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

    Can anyone tell me which theme & font is that

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

      "James Q Quick" theme and Cascadia Code font :)

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

    How does your command prompt suggest stuff?

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

      They are not suggestions, they are previously used commands

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

      @@hrushikeshvibhute4639 they were suggestions not previous commands
      and I just got it working.
      you can check this out if you want to do it too
      th-cam.com/video/ZhFFs5ltNDs/w-d-xo.html

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

    Will an api key be exposed on the frontend using this method?

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

      Well, this concept is used for running locally. In production, you'd save API keys in environment variabels in your hosting provider which is safe.

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

      Saving environment variables and getting them to work is fairly easy on Netlify but not so easy on cheaper hosting platforms that use cPanel with the Node.js web application feature. This feature allows you to store environment variables. I'm still new to this but haven't had success getting it to work. I think a video on that would be very helpful. @@JamesQQuick

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

    Volta is also a really good nvm alternative.

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

    Definitely going to ditch dotenv now. Have you tried out Remix?

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

    what is a font in vscode?

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

    Is working in react front-end

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

    Just replace everything with Bun

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

      @krtirtho show me a system writed in bun with milions of requests and users that handles tons of data, running in a production environment and qe start talking! Benchmark tests are not enough to replace a consolidated language to another one.

  • @111ramico
    @111ramico 8 หลายเดือนก่อน

    NVM ls

  • @shubhampatil5935
    @shubhampatil5935 8 หลายเดือนก่อน +1

    Use typescript. You will realize why dotenv is needed. Make videos if you have proven solution for all usecases, instead of just gaining attraction.

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

    whaat

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

    me who uses data.json file to handle data in my nodejs projekt😐

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

      Environment variables have a different use case. They're for private data such as database passwords that you don't want to upload to GitHub by mistake.

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

      @@samuelluc132 we can .gitignore it right?

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

    To long and feels overlay complicated explanation about this

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

      Thanks for the feedback. What would you change?

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

      ​@JamesQQuick its perfectly fine, short and concise, showing a caveat that you ran into, i wouldn't change a thing

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

      @@omomer3506 not short thats the point