I am working on a node, express and React app. I'm using some external API data but API token is expiring every 24 hours.First I had this saved in the .env file but I can't just update the value and use it to resend my request with a new token. Is there a good way for me to update this secret programmatically (every time my request fails with a specific error message), use it right away without restarting the server and continue using it for the next 24 hours until I have to repeat this process? If this is not possible what is the best way to go about this?
This is how I was trying to update it
module.exports = async function (req, res, next) {
const config = {
headers: {
"Accept": "application/json",
"api-token": process.env.GEO_API_KEY,
"user-email": process.env.GEO_API_EMAIL
}
}
try {
const { data } = await axios.get('url', config);
if (data.auth_token) {
process.env['GEO_API_AUTH_TOKEN'] = data.auth_token;
}
} catch (error) {
console.error(error)
}
};
but this does not update the value in .env file