Ask coding questions

← Back to all posts
.env files not working with html,css,js.
PavelDobCZ23 (0)

When I use .env files to hide important tokens and more with my html,css,js repl for a web, there's a problem that should be fixed. When viewing code, it was hidden, however when viewing as site, it was fully visible. Is there any way to disable it so my .env files are really hidden? Because making it visible through web completely canceles the point of .env file.

Answered by Baconman321 (1056) [earned 5 cycles]
View Answer
Baconman321 (1056)

.env files are more or less for programs that are run as a server and/or as a program on the VM, not for a static server (which is what a HTML, CSS, JS repl is). .env files will be fully visible and open to URLS. Besides, the .env can't be stored as an environmental variable because there is no environment (it's all just files that are served whenever a request comes in)! You also couldn't access them with JS anyways (JS is run on the client, the environmental variables don't get transferred to the client (which is probably what you don't want it to do in the first place)).

PavelDobCZ23 (0)

@Baconman321 ok, thanks for telling me, I don't understand javascript a lot, I am just starting with it so I appreciate your explanation.