Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to reference an .env in HTML script tag?

So I want to send a request to a server, this includes an API Key which must remain secret. So I want to get an .env variable to hide this. But I don’t know how to get it in a script tag in HTML.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.env files are commonly used in Node.js which is commonly used to write servers.

HTML runs in browsers, which are not Node.js and are not servers.

You cannot provide the browser with an API key while keeping it secret from the people using the browser.

You can write a webservice (e.g. using Node.js) which knows what the API key is (whether it reads it from an .env file or not) to which clients (including browsers) can make HTTP requests to.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading