Reputation: 5924
I'm running into an issue where the environment variable keys being processed by my node app are old and have since been updated. I haven't run into this behavior before, but I'm wondering if a process has cached the original version of the key value pairs and is not reading the new values associated. I am using the dotenv
module to load and use the env variables in my app and nodemon
to watch my files. Has anyone run into this issue before?
app.js
require('dotenv').config()
var express = require('express');
var app = express();
...
.env
old
AWS_KEY=AGI....
AWS_SECRET=84HE...
new
AWS_KEY=FJR...
AWS_SECRET=U3F...
console log
console.log(process.env.AWS_KEY); //AGI...
console.log(process.env.AWS_SECRET); //84HE...
nodemon.json
{
"restartable": "rs",
"ignore": [
".git",
"node_modules/**"
]
}
Upvotes: 5
Views: 3610
Reputation: 891
Run
delete process.env.VALUE_I_WANT_DELETED;
and restart your application, check the values inside process.env
See https://stackoverflow.com/a/42170366/
Upvotes: 0
Reputation: 1
as I understood yours env variables were set into global .env file. You should clean them but be more careful when you do that, this code helped me to solve the problem in mac.
while IFS='=' read -r key _; do
if [[ -n "$key" && "$key" != "#"* ]]; then
unset "$key"
fi
done < <(grep -v '^[[:space:]]*$' .env | grep -v '^#')
Upvotes: 0