Electric provides an HTTP interface to Postgres to enable a massive number of clients to query and get real-time updates to subsets of the database, called Shapes. In this way, Electric turns Postgres into a real-time database.
The TypeScript client helps ease reading Shapes from the HTTP API in the browser and other JavaScript environments, such as edge functions and server-side Node/Bun/Deno applications. It supports both fine-grained and coarse-grained reactivity patterns — you can subscribe to see every row that changes, or you can just subscribe to get the whole shape whenever it changes. The client also supports dynamic options through function-based params and headers, making it easy to handle auth tokens, user context, and other runtime values.
The client exports a ShapeStream class for getting updates to shapes on a row-by-row basis as well as a Shape class for getting updates to the entire shape.
ShapeStream
import { ShapeStream } from'@electric-sql/client'// Passes subscribers rows as they're inserted, updated, or deletedconst stream = newShapeStream({
url: `${BASE_URL}/v1/shape`,
params: {
table: `foo`,
},
})
// You can also add custom headers and URL parametersconst streamWithParams = newShapeStream({
url: `${BASE_URL}/v1/shape`,
headers: {
Authorization: 'Bearer token',
},
params: {
table: `foo`,
'custom-param': 'value',
},
})
stream.subscribe((messages) => {
// messages is an array with one or more row updates// and the stream will wait for all subscribers to process them// before proceeding
})
Shape
import { ShapeStream, Shape } from'@electric-sql/client'const stream = newShapeStream({
url: `${BASE_URL}/v1/shape`,
params: {
table: `foo`
}
})
const shape = newShape(stream)
// Returns promise that resolves with the latest shape data once it's fully loadedawait shape.rows// passes subscribers shape data when the shape updates
shape.subscribe(({ rows }) => {
// rows is an array of the latest value of each row in a shape.
}
Error Handling
The ShapeStream provides two ways to handle errors:
Postgres everywhere - your data, in sync, wherever you need it.
The npm package @electric-sql/client receives a total of 71,431 weekly downloads. As such, @electric-sql/client popularity was classified as popular.
We found that @electric-sql/client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 3 open source maintainers collaborating on the project.
Package last updated on 02 Oct 2025
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
The Socket Threat Research Team uncovered a coordinated campaign that floods the Chrome Web Store with 131 rebranded clones of a WhatsApp Web automation extension to spam Brazilian users.