Overview
Esix follows a zero-configuration philosophy. It works out of the box with sensible defaults, requiring only a MongoDB connection string to get started. All configuration is done through environment variables.Environment Variables
Esix supports three environment variables for configuration:DB_URL
MongoDB connection string. This is the only required configuration.
The connection string should include the database name. If not provided, you must set
DB_DATABASE separately.DB_DATABASE
Database name. Optional if included in the connection string.
DB_ADAPTER
Database adapter to use. Set to
'mock' for testing.| Adapter | Description | Use Case |
|---|---|---|
default | Standard MongoDB driver | Production and development |
mock | In-memory mock database | Unit tests and CI/CD |
DB_MAX_POOL_SIZE
Maximum number of connections in the connection pool.
- Low traffic: 5-10 connections
- Medium traffic: 10-25 connections
- High traffic: 25-100 connections
DB_POOL_SIZE (Deprecated)
Legacy alias for
DB_MAX_POOL_SIZE. Use DB_MAX_POOL_SIZE instead.Configuration Examples
Development Environment
Create a.env file in your project root:
.env
dotenv:
Production Environment
Set environment variables in your deployment platform:Testing Environment
Use the mock adapter for fast, isolated tests:Multiple Databases
Esix uses a global connection handler. To work with multiple databases, you can dynamically switch theDB_DATABASE environment variable:
This pattern is useful for multi-tenant applications where each tenant has a separate database.
Connection Pooling
Esix automatically manages connection pooling for optimal performance:- Connections are created on-demand when first needed
- Connections are reused across queries
- The pool size is controlled by
DB_MAX_POOL_SIZE - Connections remain open for the lifetime of your application
Manual Connection Management
For graceful shutdowns, close connections manually:Connection String Options
You can pass MongoDB connection options via the connection string:Security Best Practices
Never Commit Secrets
Keep
.env files out of version control. Add them to .gitignore.Use Strong Credentials
Use strong passwords for database users and rotate them regularly.
Limit Permissions
Create database users with only the permissions they need.
Use TLS/SSL
Enable TLS for production databases. MongoDB Atlas enables this by default.
Troubleshooting
Connection Fails
Check your connection string
Check your connection string
Verify the connection string format and credentials:
Verify network access
Verify network access
Ensure your MongoDB server is accessible:
- Check firewall rules
- Verify IP whitelist (MongoDB Atlas)
- Test with
mongoshor MongoDB Compass
Check authentication
Check authentication
Verify username and password are correct and the user has access to the database.
Invalid Adapter Error
If you see an error likemysql is not a valid adapter name:
'default' and 'mock'.
Environment-Specific Configuration
Use different.env files for each environment:
NODE_ENV: