How to handle environment variables in a React/Node.js project for production? #194209
-
🏷️ Discussion TypeQuestion BodyHi everyone, I'm building a taxi booking application (Namma-Ooru-Taxi) and I'm currently using a I’m worried about security when I deploy this to GitHub. Should I commit my Any help with the best workflow for this would be appreciated! Guidelines
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 1 reply
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
|
Hi there, please never commit your .env file to github, but add it to .gitignore immediately, and if you've already pushed it, rotate every key in it right away. For github actions, go to Settings -> Secrets and variables -> Actions and add each secret individually. |
Beta Was this translation helpful? Give feedback.
-
|
Never commit .env to GitHub. Add it to .gitignore. If pushed, rotate all secrets immediately. For GitHub Actions, store secrets in Settings → Secrets and variables → Actions. Better than just adding them individually: Use GitHub Environments (dev/staging/prod) with separate secret sets. Reference as ${{ secrets.KEY }} in your workflow. Add a .env.example file to your repo so others know what's needed. |
Beta Was this translation helpful? Give feedback.
-
|
Hey mahmoudnajmeh, I think there is some misunderstanding. If anything, my answer went a step further by also including github actions secrets setup, deployment server best practices, and per environment key separation. |
Beta Was this translation helpful? Give feedback.
-
|
Hey, you should never commit your .env file, this file is to save your secret keys, passwords, any type of information that cant be public. You must always put .env in .gitignore. It stays only in your pc to test the app. Furthermore, when you put your application online, there are many ways to use this keys online without making them public, like Environment Variables on vercel or AWS Secrets Manager. |
Beta Was this translation helpful? Give feedback.
Hi! Great question. You should never commit your
.envfile to GitHub because it contains sensitive secrets.Here is the best practice:
.envto your.gitignorefile immediately..env.examplewith the keys but no real values (e.g.,API_KEY=your_key_here) so others know what is needed.This keeps your keys safe while allowing your app to run!