To set up a secure environment with your .env
file and replace sensitive keys in your project, follow these steps:
-
Create the
.env
File:In your project root, create a file named
.env
and paste the following variables:PORT=3001 MONGO_URI="mongodb+srv://Ashish:[email protected]/userCredentials" FRONTEND_URL="http://localhost:3000"
Note: Avoid committing this file to version control, as it contains sensitive information. Add
.env
to your.gitignore
file if it’s not there already. -
Replace the Gemini API Key in
Bot.js
:Go to
client/src/Components/Bot.js
, locate line 21, and replace the placeholder with your actual API key. Format it as follows:url: process.env.GEMINI_API_KEY,
-
Add
GEMINI_API_KEY
to.env
:In your
.env
file, add theGEMINI_API_KEY
like this:GEMINI_API_KEY="your_actual_api_key_here"
-
Configure Environment Variable Access:
If you're using
dotenv
(in Node.js), make sure to load environment variables at the top of your server file:require('dotenv').config();
-
Frontend Configuration:
To access environment variables in the frontend, prefix them with
REACT_APP_
in.env
. Update.env
:REACT_APP_GEMINI_API_KEY="your_actual_api_key_here"
And then update
Bot.js
:url: process.env.REACT_APP_GEMINI_API_KEY,
This ensures your keys are securely managed while the application runs smoothly.