How can I use a .env in a JSON file?
I already have a .env file with my key in it, but right now I just need to be able to access it through the JSON file.
How can I do that?
Hello, assuming you are coding in
node.js, there is a very sneaky way to do it. First, do
JSON.stringify() on the JSON file. For example:
const json = require("./path/to/json.json") console.log(JSON.stringify(json));
Now, copy the output, and put it inside your
JSON=[insert json here]
Now, anytime you want to access it,
const output = JSON.parse(process.env.JSON)
Hopes this helps!
If you are talking about this repl:
let secret = process.env.SECRET
and in your .env file