Required Variables
MONGODB_URI
Required: YesType: String
Description: MongoDB connection string The connection string for your MongoDB database. Supports both standard and SRV formats.
MONGODB_DB
Required: NoType: String
Default:
portafolioDescription: Database name to use in MongoDB Specifies which database to query for NFQ events.
MONGODB_COLLECTION_NFQ
Required: NoType: String
Default:
nfqDescription: Collection name for NFQ events Specifies which collection contains the NFQ (No Failure Questions) events.
Configuration by Environment
Local Development
Create a.env file in the project root:
dotenv to load these variables:
The
override: false option means environment variables already set in process.env take precedence over the .env file.Docker Deployment
Pass environment variables when running the container:Cloud Platforms
Each cloud platform has its own method for setting environment variables:Security Best Practices
Protecting Credentials
- Add to .gitignore
-
Use secrets management for production:
- AWS Secrets Manager
- Google Secret Manager
- Azure Key Vault
- HashiCorp Vault
- URL-encode special characters in connection strings:
- Rotate credentials regularly and update environment variables
- Use read-only credentials when the application doesn’t need write access
Environment-Specific Variables
Maintain separate configurations for each environment:Validation
The application validates thatMONGODB_URI is set at runtime:
Example .env File
Here’s a complete example.env file:
Troubleshooting
Variable Not Loading
- Verify
.envfile is in the project root - Check file has no syntax errors (no spaces around
=) - Restart the development server after changes
- Ensure the file is not named
.env.txtor similar
Connection String Issues
- Special characters: URL-encode special characters in passwords
- Whitespace: Remove any trailing spaces from values
- Quotes: Don’t use quotes around values in
.envfiles
Production vs Development
If variables work locally but not in production:- Verify environment variables are set in your deployment platform
- Check that the platform restarts the application after setting variables
- Review platform-specific logs for configuration errors
- Ensure secrets are not masked or truncated
Next Steps
MongoDB Setup
Configure MongoDB database and collections
Docker Deployment
Deploy using Docker containers