How to generically update an existing environment variable to .env file?

I am using dotenv to load env variables and use in my mocha test. But based on a function that is generating a new token value for one of the existing environment var, I want to be able to generically update its value to .env file. Is it possible?

testSpec.js :

const webapi = require('../libs/webapi')

async function getVal() {
//to generate a new token using existing one
token = webapi.generate( process.env.BASE_URI, process.env.C_KEY, process.env.AUTH_TOKEN)
token.then(response => {
        obj = JSON.parse(response.body)
        authToken = obj.auth_token

.env :


From testSpec.js generate() generates a new token value that I’m parsing i.e; authToken ; that I want to generically update in the .env file for AUTH_TOKEN var in place of its previous value. Is it possible to write/update to .env for its updated value through some lib? I am new to nodejs and using npm packages, any help appreciated.

25 thoughts on “How to generically update an existing environment variable to .env file?”

  1. 510517 239509That being said by use it all, planet is genuinely restored a little much more. This situation in addition will this specific Skin tightening and starting to be moved and into the mood of these producing activities. everyday deal livingsocial discount baltimore washington 80016

  2. 923175 898927omg! cant envision how quick time pass, right after August, ber months time already and Setempber could be the very first Christmas season in my spot, I truly enjoy it! 246356

  3. <