title: Installation description: Install and configure Eloquent ORM JS in your Node.js project.
Installation and Quick Start
Version:1.1.4
Install
dotenv and @faker-js/faker stay in the package runtime dependencies because the published runtime uses them:
dotenvis used by the default database config bootstrap.@faker-js/fakeris used by the factory runtime surface and generated factory flow.
dotenv.config() or your own code imports faker directly, add them in your app too:
ESM and NodeNext imports
NodeNext and ESM apps can import the public runtime directly from the package root:import consumers through an ESM-safe entry while keeping CommonJS require() usage safe for plain root imports that do not need the factory runtime.
npm package discovery
These npm metadata commands now resolve directly to the hosted docs, GitHub repository, and issue tracker:Prerequisites
The following versions are the current supported and CI-tested prerequisites.| Component | Supported / tested version | ||||
|---|---|---|---|---|---|
| Node.js | `^20 | ^22 | ^24` | ||
| TypeScript | ^5.9.3 | ||||
| MySQL | 8.0 | ||||
| PostgreSQL | 16 | ||||
| MongoDB | 7 | ||||
| SQLite | SQLite 3.x via better-sqlite3 12.2.0 | ||||
| Memcached | 1.6+ server, client package ^2.2.2 |
Full .env setup
Use one active value in DB_CONNECTION and one active value in DB_TEST_CONNECTION.
Do not put multiple connection names in the same env variable.
Quick .env key list
DB_CONNECTION: active app connection name such asmysql,pg,sqlite, ormongoDB_TEST_CONNECTION: active test connection name such asmysql_test,pg_test,sqlite_test, ormongo_testELOQUENT_DB_ROLE: chooseruntimefor the app process andmigrationonly for migration or reset jobsAPP_ENV: usedevelopmentfor local work andproductiononly for real production processesDB_*andDB_TEST_*: MySQL runtime and test credentialsPG_*andPG_TEST_*: PostgreSQL runtime and test credentialsSQLITE_PATHandSQLITE_TEST_PATH: SQLite database filesMONGO_URI,MONGO_DB,MONGO_TEST_URI, andMONGO_TEST_DB: Mongo runtime and test targetsMEMCACHED_HOSTandMEMCACHED_PORT: Memcached endpoint for production cache modeCACHE_DIR: file-cache fallback directory used in staging and in the production fallback chain
.env constant reference
Connection selectors
DB_CONNECTION: default application connection. Use one value such asmysql,pg,sqlite, ormongo.DB_TEST_CONNECTION: default isolated test connection. Use one value such asmysql_test,pg_test,sqlite_test, ormongo_test.ELOQUENT_DB_ROLE: credential role selector. Useruntimefor normal app traffic andmigrationfor migration or reset jobs.APP_ENV: deployment mode. Usedevelopmentfor local work andproductiononly for real production processes.
MySQL constants
DB_HOST: MySQL host or IP for runtime traffic.DB_PORT: MySQL port for runtime traffic. Usually3306.DB_USER: MySQL username for runtime traffic.DB_PASSWORD: MySQL password for runtime traffic.DB_NAME: MySQL database name for runtime traffic.DB_TEST_HOST: MySQL host or IP for isolated test traffic.DB_TEST_PORT: MySQL port for isolated test traffic.DB_TEST_USER: MySQL username for isolated test traffic.DB_TEST_PASSWORD: MySQL password for isolated test traffic.DB_TEST_NAME: MySQL database name for isolated test traffic.
PostgreSQL constants
PG_HOST: PostgreSQL host or IP for runtime traffic.PG_PORT: PostgreSQL port for runtime traffic. Usually5432.PG_USER: PostgreSQL username for runtime traffic.PG_PASSWORD: PostgreSQL password for runtime traffic.PG_NAME: PostgreSQL database name for runtime traffic.PG_TEST_HOST: PostgreSQL host or IP for isolated test traffic.PG_TEST_PORT: PostgreSQL port for isolated test traffic.PG_TEST_USER: PostgreSQL username for isolated test traffic.PG_TEST_PASSWORD: PostgreSQL password for isolated test traffic.PG_TEST_NAME: PostgreSQL database name for isolated test traffic.
SQLite constants
SQLITE_PATH: file path for the runtime SQLite database.SQLITE_TEST_PATH: file path for the isolated test SQLite database.
MongoDB constants
MONGO_URI: MongoDB connection string for the runtime database.MONGO_DB: runtime MongoDB database name.MONGO_TEST_URI: MongoDB connection string for the isolated test database.MONGO_TEST_DB: isolated test MongoDB database name.
Cache constants
MEMCACHED_HOST: Memcached host or IP used in production cache mode.MEMCACHED_PORT: Memcached port used in production cache mode. Usually11211.CACHE_DIR: file-cache directory used in staging and as a fallback in production.
Runtime role and environment mode
Use these two variables together:ELOQUENT_DB_ROLE=runtime- normal app runtime
- Express requests
- controllers, services, and standard CRUD traffic
ELOQUENT_DB_ROLE=migration- migration commands
- reset or fresh flows
- controlled schema-change jobs
APP_ENV=development- your local machine
- normal development and testing
APP_ENV=production- real production deploys
- production migration jobs
Cache environment keys
WhenAPP_ENV=production, cache setup uses this fallback chain:
- Memcached
- file cache
- memory cache
MEMCACHED_HOSTdefaults to127.0.0.1MEMCACHED_PORTdefaults to11211CACHE_DIRdefaults to.cache
Example SQL-first environment
Mongo example environment
Quick start
- Install the package and Express.js.
- Add the
.envkeys for your active driver. - Register models at app startup.
- Generate and run migrations.
- Seed data and run a scenario check.
.env minimum for a SQLite start:
Runtime bootstrap example
This ORM runtime is designed to work smoothly with Express.js in HTTP applications. If your app exposes routes, keep Express.js at runtime; examples assume this setup.SqlModel for SQL-backed models and MongoModel for Mongo-backed models.
Example SQL model: