Overview
The portfolio uses environment variables to securely store sensitive configuration data, primarily for the EmailJS integration in the contact form. Location: Create a.env file in the project root
Required Variables
All environment variables in Vite must be prefixed withVITE_ to be exposed to the client-side code.
EmailJS Configuration
The contact form requires three EmailJS credentials:Your EmailJS service identifier.Used in:
/src/components/Contact/Contact.jsx:22How to get:- Sign up at EmailJS
- Go to Email Services
- Add a new service (Gmail, Outlook, etc.)
- Copy the Service ID
service_abc123xyzYour EmailJS email template identifier.Used in:
/src/components/Contact/Contact.jsx:23How to get:- In EmailJS dashboard, go to Email Templates
- Create a new template or use an existing one
- Configure template with variables:
{{name}},{{email}},{{message}} - Copy the Template ID
template_xyz789abcYour EmailJS public API key.Used in:
/src/components/Contact/Contact.jsx:29How to get:- In EmailJS dashboard, go to Account
- Find your Public Key (or create one)
- Copy the key
Abc123XyzPublicKeySetup Instructions
Step 1: Create .env File
In the project root directory, create a.env file:
Step 2: Add Variables
Add your EmailJS credentials to the.env file:
Step 3: Verify .gitignore
Ensure.env is in your .gitignore:
Step 4: Restart Dev Server
After adding environment variables, restart your development server:.env.example Template
Create a.env.example file to help other developers set up the project:
Usage in Code
Access environment variables usingimport.meta.env:
EmailJS Template Configuration
Your EmailJS template should include these variables:Environment-Specific Variables
Vite supports different environment files:.env- All environments.env.local- All environments, ignored by git.env.development- Development only.env.production- Production only
Security Best Practices
Do’s
- Use environment variables for service IDs and public API keys
- Add
.envto.gitignore - Provide
.env.examplefor team members - Use different credentials for development and production
- Rotate keys regularly
Don’ts
- Never commit
.envfiles - Don’t store database passwords in
VITE_variables - Don’t use private API keys on the client side
- Don’t hardcode credentials in source files
Deployment
Vercel
Add environment variables in your Vercel project settings:- Go to Project Settings > Environment Variables
- Add each variable:
VITE_EMAILJS_SERVICE_IDVITE_EMAILJS_TEMPLATE_IDVITE_EMAILJS_PUBLIC_KEY
- Select environment (Production, Preview, Development)
- Redeploy
Netlify
- Go to Site Settings > Build & Deploy > Environment
- Click “Edit variables”
- Add your variables
- Trigger a new deploy
Other Platforms
Most hosting platforms provide a way to set environment variables through their dashboard or CLI. Consult your platform’s documentation.Troubleshooting
Variables Not Loading
Problem:import.meta.env.VITE_EMAILJS_SERVICE_ID is undefined
Solutions:
- Ensure variable has
VITE_prefix - Restart dev server after adding variables
- Check
.envfile is in project root - Verify no syntax errors in
.env(no quotes needed)
Contact Form Not Sending
Problem: Email not being sent when form is submitted Solutions:- Verify all three EmailJS variables are set
- Check EmailJS dashboard for correct IDs
- Ensure EmailJS service is active
- Check browser console for errors
- Verify template variables match:
{{name}},{{email}},{{message}}
Building for Production
Problem: Variables work in dev but not in production build Solutions:- Set environment variables in your hosting platform
- Don’t rely on local
.envfor production - Rebuild after setting variables
Additional Variables
If you add more features requiring environment variables:VITE_ and update .env.example.