Installation
Add Commercio to your Node.js project.
npm install commercioRequirements
- Node.js 18+ or Bun
- PostgreSQL 14+, MySQL 8+, or SQLite 3.35+
- TypeScript 5+ (recommended)
Database Driver
Install the driver for your database. Commercio supports PostgreSQL, MySQL, and SQLite.
npm install pgConfiguration
PostgreSQL
import { initDatabase } from "commercio";
await initDatabase({
dialect: "postgresql",
connectionString: "postgresql://user:password@localhost:5432/my_erp_db",
runMigrations: true,
});You can also set DATABASE_URL as an environment variable. The package reads it automatically.
Migrations
Set runMigrations: true in your config to run migrations automatically on startup. Or run them manually:
import { initDatabase, runMigrationsWithDb, db } from "commercio";
await initDatabase({
dialect: "postgresql",
connectionString: process.env.DATABASE_URL,
});
// Run migrations explicitly
await runMigrationsWithDb(db);