Home > Enterprise >  .env variables are returning undefined after adding it to gitignore
.env variables are returning undefined after adding it to gitignore

Time:01-29

Need some help here.

I'm using environmental variables to hide my keys and using .gitignore to ignore the .env in my repository so nobody could see it. The authentication of mailchimp API works locally, and if I input data on email and names, it gets added to my mailchimp.

enter image description here

But when I deploy it to render and github, it sure makes my .env hidden so nobody could see my API. But the variable returns undefined. I added the .env in my .gitignore, I don't know if that's causing the problem? Pls help me.

enter image description here

I tried logging the values of my API. It shows the value properly if I do it in local. But in console logs of Render, it returns undefined. Am I missing something here? Could it be that gitignore, literally ignores my env file, hence, MAPI_SERVER, MAPI_KEY, MLIST_ID couldn't get it values?

CodePudding user response:

You should add environment variables to Render as documentation: https://render.com/docs/configure-environment-variables

CodePudding user response:

The file is not on the server.

Adding the file to .gitignore¹ makes it not being tracked by git. This means that the file is not in your remote repo.

You could:

  1. Deploy the file to the server via some other means
  2. Set the environment variables on the some other way

I'd recommend to keep the file outside of the repo to minimise the chance of accidentally committing it.²


¹ - if the file was already added then it will stay added
² - there are ways to commit ignored files

  • Related