I am currently working on setting up a .env
file to securely store the credentials for my Firebase database within a vanilla JavaScript project. Despite following various tutorials and referencing the documentation for dotenv, I continue to encounter an error message stating
Uncaught ReferenceError: require is not defined
. Can anyone identify what might be causing this issue?
Below is the snippet of code contained within the <script>
tags in my index.html
file where the sensitive information from the .env
file is being utilized:
require('dotenv').config();
// Initialize Firebase
var config = {
apiKey: process.env.API_KEY,
authDomain: process.env.AUTH_DOMAIN,
databaseURL: process.env.DATABASE_URL,
projectId: process.env.PROJECT_ID,
storageBucket: process.env.STORAGE_BUCKET,
messagingSenderId: process.env.MESSAGING_SENDER_ID
};
firebase.initializeApp(config);