How to add Environment Variables in Next.JS | Using dot-files(.env) and next.config.js

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

КОМЕНТАРІ • 19

  • @MayankSrivastava
    @MayankSrivastava  9 місяців тому

    Go watch my new video on deploying Next.JS apps on the web: ua-cam.com/video/ACYbIVvdPq0/v-deo.html

  • @alvaronaffa6150
    @alvaronaffa6150 11 місяців тому +1

    Great video 👏

  • @danieltan3163
    @danieltan3163 Рік тому +2

    I had been struggling to understand why my .env variables have been printing "undefined" for a while now which had set me back on my project. Thanks to your explanation, I now understand that its because Nextjs won't render the .env variable in the client side but only to the server side. Thank you so much!

  • @nikhiljain7403
    @nikhiljain7403 Рік тому +2

    the best video for env on nextJS but still it does not work for me specifically for priority points like running on the development server still m getting value from the .env file rather than .env.development. can you please help me with this?

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

    Extremely useful! Thank you!

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

    Very useful. Thank you

  • @JacaRanda-br4lg
    @JacaRanda-br4lg 2 роки тому

    THANKS SO MUCH IT HELPED A LOTT!!!!!

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

    Thanks! great content! I have a request. Please use the latest version of Nextjs and any other package you use like apollo, or RTK

  • @DemiZhao-pi7qp
    @DemiZhao-pi7qp Рік тому

    Great content, thanks

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

    Thank you

  • @nihalpadwal
    @nihalpadwal 2 роки тому +2

    Hey Mayank, loved the video i just had one thing to ask you, you see i made a website using next and getServerSideprops and deployed to netlify but whenever i open the link it gives me 500 internal server error. i have other pages where i havent used server side props and in that same website and when i navigate to those pages using url those pages works fine , only pages where i use server side props give 500 internal server error
    hope you see this and waiting for a solution :)

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

      Hey Nihal, a 500 error is thrown when there is a failure on the server side. The issue is likely with the implementation of your getServerSideProps function eg. API endpoint not available, env variable not loading etc.
      Can you share the function so I can take a look

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

    Hi Mayank, Great Content bro, it helped me in knowing which command to run the app in prod env. i was struggling to find out this from past two hours.
    also can you tell which command to run the app in staging/test env.
    basically i want to know how to set the app to read .env.test
    for ex:
    if we "yarn dev", it is taking .env.local
    if we run "yarn start", it is taking .env.production
    what is it for .env.test??

    • @MayankSrivastava
      @MayankSrivastava  9 місяців тому

      while running your app in test mode, basically for e2e and unit tests