Reputation: 964
I have searched and searched for a straight forward answer to this question but I have found nothing. I have my local .env file and am successfully loading it with dotenv.
The only answer I can find for setting up the process.env variables for production is to use Elastic Beanstalk.
Is there a way to set these variables up with just an EC2 instance?
Upvotes: 2
Views: 4006
Reputation: 902
if [[ ! -d "$MyVar" ]]; then
export MyVar="abc"
echo 'export MyVar="abc"' >> ~/.bashrc
fi
use this code. it saves MyVar in ~/.bashrc permanently
Upvotes: 0
Reputation: 669
For Ubuntu based (Linux) EC2 Instances
Edit ~/.bashrc file of User which will run the program
sudo nano ~/.bashrc
Add following line at the end, use any variable_name. Assuming unique and unused
export API_KEY=btgj32fkf
Save File and
source ~/.bashrc
Now, in node program process.env.API_KEY will be available.
For different operating System of EC2, method above will slightly change
Upvotes: 2
Reputation: 7237
It's a normal server. you can always set env by
EXPORT FOO=bar
Upvotes: 0