Skip to content

TypeScript & JavaScript SDK

Install the official JavaScript SDK:

Terminal
pnpm add pocketbase

Initializing the Client

src/pb.ts
import PocketBase from 'pocketbase';
export const pb = new PocketBase('https://<your-subdomain>.pocket-kit.naftalmatoya.tech');
// Auto-cancellation can be disabled if running concurrent requests in React:
pb.autoCancellation(false);

Authentication & CRUD Operations

src/operations.ts
// 1. Password Authentication
const authData = await pb.collection('users').authWithPassword('user@example.com', 'password123');
// 2. Fetch Paginated Records
const resultList = await pb.collection('posts').getList(1, 20, {
filter: 'created >= "2026-01-01" && active = true',
sort: '-created',
});
// 3. Create a Record
const newPost = await pb.collection('posts').create({
title: 'Hello from Pocket Kit',
content: 'PocketBase single-tenant cloud deployment.',
views: 1,
});
// 4. Realtime Subscriptions (SSE)
pb.collection('posts').subscribe('*', function (e) {
console.log('Realtime event action:', e.action);
console.log('Record data:', e.record);
});