0

I have a check.env file, in which I have some variables like SharedAccessKey=

I want to put a value in the check.env file from my node.js code. Articles on internet are there for updating at the running time of node.js, but my requirement is to change in the file and keep the file with changes made.

How can I accomplish that.

I got this link : How to change variables in the .env file dynamically in Laravel?

but it is in some other language, how can I do in node.js.

Anki
  • 67
  • 1
  • 12

1 Answers1

0

I was unable to find out the best solution so went with another solution of mine that I took.

  1. I am using two files now both .env extensions and I am copying main .env file to another empty .env file (like check1.env to check2.env).

  2. Any modifications I am making is in the second file (check2.env).

  3. And I am using string replacement in the .env file, using fs.readLine() and getting the string and the data.replace(), this worked for me.

The reason to use two .env files is that even if I change in the second file, again by copying from the first file I will get same string search and will replace with a different value.

-- Please suggest if there is an any better approach. Thanks

Anki
  • 67
  • 1
  • 12