PGlite Embeddable WASM Postgres for Browser and Node.js
PGlite is a WASM build of Postgres packaged as a TypeScript library that runs a full Postgres database in the browser, Node.js, Bun, and Deno. At only 3.7MB gzipped, it enables local-first applications with real SQL capabilities and no external database dependencies.
Installation
Use the upstream install or setup path that matches your environment:
- npm install @electric-sql/pglite
- Docker is required to build the WASM module, along with Node (v20 or above) and pnpm for package management and building the TypeScript packages.
- git clone --recurse-submodules https://github.com/electric-sql/pglite
- pnpm install
Requirements and caveats from upstream:
- PGlite is a WASM Postgres build packaged into a TypeScript client library that enables you to run Postgres in the browser, Node.js, Bun and Deno, with no need to install any other dependencies. It is only 3mb gzipped...
- It can be used as an ephemeral in-memory database, or with persistence either to the file system (Node/Bun/Deno) or indexedDB (Browser).
Node/Bun/Deno
Basic usage or getting-started notes:
NodeJS
bash
Bun
Extracted from upstream docs: https://raw.githubusercontent.com/electric-sql/pglite/HEAD/README.md