Deploy
The usual setup is the PGlite in dev, Postgres in prod one: the server side is disabled, the development socket serves PGlite while nuxt dev runs, and production connects to a real Postgres. Your database code reads a connection string from the environment and uses an ordinary driver, so nothing changes between the two but the value of that variable.
export default defineNuxtConfig({
modules: ['nuxt-pglite'],
pglite: {
server: {
enabled: false, // nothing of PGlite in the build
},
socket: { port: 5433 }, // `DATABASE_URL` while `nuxt dev` runs
},
})
The environment
nuxt dev | Production | |
|---|---|---|
DATABASE_URL | the socket's URL, unless already set | set by you, or by your platform |
| Driver | yours (pg, postgres.js, Drizzle, …) over the wire protocol | the same |
server/pglite.config.ts | loaded by the socket | not bundled |
@electric-sql/pglite in the server output | n/a | absent |
DATABASE_URL is the socket's default variable, and the one most hosts and tools use. A platform that provisions the database itself may set another name: socket.provider exports that one instead, so code written for the platform reaches the socket unchanged. A variable already set in your environment always wins over the socket, so a .env pointing at a real database is respected in development too.
The two migration models
The schema comes from a folder of SQL migration files. In development, init applies them to PGlite with applyMigrations. In production, who applies them depends on the platform:
| You apply | The platform applies | |
|---|---|---|
| Where | the build command or a CI job, with the production URL | the platform, from the files committed with your app, on deploy |
| How | drizzle-kit migrate (or your tool's migrate), or applyMigrations with fromPool | nothing to run: commit the files where the platform reads them, and never push or migrate against its database |
| Example | Any Postgres, Neon | Netlify Database |
Either way, the local database and the production one are built from the same files, and a file edited after it was applied is caught locally before it reaches production.
PGlite in production
If you deploy with the server side enabled, PGlite itself runs in production and needs a writable, persistent data directory: a Node server or a container with a volume, not a serverless function. Set it with NUXT_PGLITE_DATA_DIR, and keep applyMigrations in init pointed at a directory that exists at runtime.