Ask coding questions

← Back to all posts
How can I use a .env in a JSON file?
Ipex

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?

Voters
joshuaiyer22
Ipex
Comments
hotnewtop
Coder100

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:

Now, copy the output, and put it inside your .env file:

Now, anytime you want to access it,

Hopes this helps!

seanlnge

If you are talking about this repl:

https://repl.it/@Ipex/MA-Cafe-Bot#bot.js

then all you have to do is do something in your javascript code such as:

and in your .env file
SECRET: abjoiuegouuefk90j

You can put that secret through the JSON file from your javascript

coderash

what llanguage are u using with json? if python:
os.getenv(KEY)

TheForArkLD

wdym?