How to use an .ENV file with a website

3.7k Views Asked by At

I've made a few node.js bots and web applications that have used .env variables along with the dotenv package to hold all of the API keys.

However, Im currently working on a website that uses node.js with browserify and this method doesn't seem to work. Whenever I try to output the value to the console or use the value in the code it returns undefined.

How would I fix this, or if .env's simply don't work on the web, how would I hide these values?

my .env example

ID = B1CRL2WDIW2553
SECRET = 41445d2b99b33ede3ebce0421900b8e9

my js example

const dotEnv = require('dotenv').config({path: './.env'});
console.log(process.env.ID);

example of the return statement enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

I resolved this by adding the API keys and privileged info to the firebase database and then checking for user authentication before handing over the information. A tutorial can be found here: https://firebase.google.com/docs/database/security/