Recipes

Deploy

[object Object]

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.

nuxt.config.ts
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 devProduction
DATABASE_URLthe socket's URL, unless already setset by you, or by your platform
Driveryours (pg, postgres.js, Drizzle, …) over the wire protocolthe same
server/pglite.config.tsloaded by the socketnot bundled
@electric-sql/pglite in the server outputn/aabsent

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 applyThe platform applies
Wherethe build command or a CI job, with the production URLthe platform, from the files committed with your app, on deploy
Howdrizzle-kit migrate (or your tool's migrate), or applyMigrations with fromPoolnothing to run: commit the files where the platform reads them, and never push or migrate against its database
ExampleAny Postgres, NeonNetlify 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.

Any Postgres

DATABASE_URL and a migrate step in the build.

Netlify

Netlify Database applies the committed files on deploy.

Neon

Serverless drivers in production, pg against the socket.