Rebase was built to be completely modular. While the initializeRebaseBackend coordinator provides a full batteries-included backend using Hono, you can completely bypass it and embed the core Database Adapter and Realtime WebSockets directly into your own custom Node.js application (like Express, Fastify, or plain Node.js HTTP).
The @rebasepro/server-postgres package is completely framework-agnostic. It depends only on Drizzle ORM and standard Node.js http.Server.
Rebase provides a centralized loadEnv() utility in @rebasepro/server that validates your environment variables against a strict Zod schema. Call it after loading your .env file:
Here is a complete example of how to initialize the Rebase PostgreSQL adapter and Realtime WebSockets inside a standard Express application, manage read replicas, access Drizzle directly, and implement clean server terminations.
Standard path: if your server uses initializeRebaseBackend (like the scaffolded template does), don’t hand-roll the shutdown handler above — use the built-in helper instead. It drains HTTP, stops the cron scheduler, tears down realtime services, guards against repeated signals, and force-exits if shutdown hangs:
Do not combine it with your own server.close() — backend.shutdown() already closes the server, and a second close deadlocks. The manual handler shown in the example above is only for fully custom setups that bypass initializeRebaseBackend.
If you define the DATABASE_READ_URL environment variable, Rebase automatically spawns a secondary connection pool targeting your read replica. The bootstrapper registers this under internals.readDb. The core EntityFetchService routes all SELECT queries to the replica pool to optimize performance, while mutation queries remain on the primary pool.
You do not have to choose between Rebase and Drizzle. The bootstrapper compiles your schemas dynamically. You can access the compiled Drizzle NodePgDatabase client via internals.db, allowing you to run raw SQL migrations or invoke type-safe Drizzle builders alongside Rebase’s REST services.
In serverless environments or orchestrators (like Kubernetes), terminating pods can result in broken connections. Always implement signal handlers that invoke realtimeProvider.stopListening() (which terminates the dedicated pg LISTEN client) and pool.end() to prevent leaking connection slots in your database server.
Cookie Preferences
We use cookies to
enhance your browsing experience and analyze our traffic.
By clicking "Accept", you consent to
our use of
cookies.