Skip to main content


ElectricSQL supports Node.js server applications using the node-postgres driver.


Add pg as a dependency to your app, e.g.:

npm install pg


// Import the node-postgres database client.
import pg from 'pg'

// Import the adapter to electrify node-postgres from the ElectricSQL library.
import { PGlite } from '@electric-sql/node-postgres'

// Import your generated database schema.
import { schema } from './generated/client'

// Define custom configuration if needed
const config = {
url: ''

// Create the node-postgres database connection.
const conn = new pg.Client({
// Connection configuration, see:
await conn.connect()

// Instantiate your electric client.
const electric = await electrify(conn, schema, config)

// Connect to the sync service, passing along your authentication token
// See Usage -> Authentication for more details.
await electric.connect('your token')

You can now use the client to read, write and sync data, e.g.:

const { db } = electric

const results = await db.projects.findMany()

See Usage -> Data access and Integrations -> Frontend for more information.