Install Esix
Esix requires Node.js 20 or higher and works with MongoDB 4.0+.Esix has
mongodb as a peer dependency. You must install both esix and mongodb packages.Configure MongoDB connection
Esix automatically connects to MongoDB when needed. Configure your connection using environment variables:Set connection string
The simplest way to configure Esix is with theDB_URL environment variable:
Environment variables reference
Esix supports the following environment variables:MongoDB connection string. This is the primary configuration option and the only required variable.
Database name. Optional—Esix extracts the database name from
DB_URL if not provided.Database adapter. Set to
'mock' for testing with in-memory MongoDB. Defaults to the standard MongoDB driver.Verify installation
Create a simple test file to verify your installation:test.ts
TypeScript configuration
Esix requires the following TypeScript compiler options in yourtsconfig.json:
tsconfig.json
Testing setup
For testing, you can use an in-memory MongoDB mock or a test database:Option 1: Mock adapter (recommended for unit tests)
Install the mock adapter:Option 2: Dedicated test database
Use a separate database for testing:Docker setup
If you need a local MongoDB instance for development, use Docker:Connection management
Esix automatically manages your MongoDB connection:- Lazy connection: The connection is established when you first query the database, not when your application starts
- Connection pooling: MongoDB’s native connection pooling is used automatically
- No manual cleanup: You don’t need to explicitly close connections
The automatic connection management means you can start writing queries immediately without any initialization code.
Next steps
Quickstart
Build your first Esix application with a complete working example