Overview
BillBuddy uses environment variables to configure the application’s runtime behavior. All environment variables should be defined in a.env file in the backend directory.
Never commit your
.env file to version control. The .gitignore file is already configured to exclude it.Creating the Environment File
Create a.env file in the backend directory of your BillBuddy installation:
Required Variables
The following environment variables are required for BillBuddy to function properly:The port number on which the Express server will listen for incoming requests.
MongoDB connection string for database connectivity. Supports both local and cloud MongoDB instances.Local MongoDB:MongoDB Atlas:
Secret key used for signing and verifying JSON Web Tokens (JWT) for user authentication.Generating a secure secret:
Access key for Web3Forms email service used to send settlement summaries to users.Get your access key from Web3Forms
Complete Example
Here’s a complete example.env file with all required variables:
Environment-Specific Configuration
Development
For local development, use the following configuration:Production
For production deployment, use:Loading Environment Variables
BillBuddy uses thedotenv package to load environment variables. The configuration is automatically loaded in server.js:
backend/server.js
Accessing Variables in Code
Environment variables are accessed throughout the application usingprocess.env:
Validation
To verify your environment variables are loaded correctly, start the server and check the console output:If you see connection errors, verify that your
MONGODB_URI is correct and that MongoDB is running.Troubleshooting
Variables Not Loading
If environment variables aren’t loading:- Ensure the
.envfile is in thebackenddirectory - Check that variable names match exactly (case-sensitive)
- Restart the server after making changes
- Verify no trailing spaces in variable values
MongoDB Connection Issues
If MongoDB connection fails:- Verify MongoDB is running locally:
mongod --version - Check the connection string format
- For Atlas, ensure IP whitelist includes your address
- Verify credentials are correct
JWT Errors
If authentication fails:- Ensure
JWT_SECRETis set and not empty - Use the same secret across all server instances
- Check token expiration (default: 30 days)