Skip to main content

Getting started

Prerequisites

info

Prisma Pulse currently supports PostgreSQL. We'd love to hear which databases you would like to see supported next.

To get started with Pulse, you will need the following:

1. Enable Pulse

Navigate to your Prisma Data Platform project, choose an environment, and enable Pulse. We'll connect to your database and verify connectivity during setup.

Once enabled, you'll be prompted to generate an API key that you'll use in your extended Prisma Client to authenticate requests. Store this API key in your application's .env file:

.env
PULSE_API_KEY="your_secure_pulse_api_key"

2. Add Pulse to your application

With Pulse enabled, proceed with these steps to integrate Pulse into your application. You can also utilize our example repository on GitHub as a reference guide.

2.1. Install the Pulse Client extension

info

Pulse requires Prisma Client version 4.16.1 or higher and @prisma/extension-pulse version 1.0.1 or higher

Install the latest version of Prisma Client and the Pulse Client extension

npm install @prisma/client@latest @prisma/extension-pulse@latest

2.2. Extend your Prisma Client instance with the Pulse extension

Add the following to extend your existing Prisma Client instance with the Prisma Pulse extension:

import { PrismaClient } from '@prisma/client'
import { withPulse } from '@prisma/extension-pulse'

const prisma = new PrismaClient().$extends(
withPulse({ apiKey: process.env.PULSE_API_KEY })
)
note

You stored this API key in your .env file after enabling Pulse. If needed, you can navigate to your respective project environment and generate a new API key.

2.3. Create your first Pulse subscription

With the Pulse extension applied, you can use Pulse's subscribe() method on any model defined in your Prisma Schema to subscribe to data change events.

In the below example, a subscription is made to a notification model that listens for any change event on that table:

const prisma = new PrismaClient().$extends(withPulse({ apiKey: apiKey }))

async function main() {
const subscription = await prisma.notification.subscribe()

for await (const event of subscription) {
console.log('just received a notification:', event)
}
}

main()

All done! You've successfully added Pulse to your application. Explore next steps to learn more.

Next steps

Navigate to the API section to explore available filtering options for Pulse's subscribe() method.

const subscription = await prisma.notification.subscribe({
create: {
userId: 123, // subscribe to all notifications created for the user with ID 123
},
})

Need help?

Reach out to us in the #help-and-questions channel on our Discord, or connect with our community to see how others are using Pulse.