JavaScript SDK usage for PocketBase client applications. Use when calling PocketBase from frontend or Node.js, authenticating users, subscribing to realtime events, uploading files, or working with the PocketBase JS/TS SDK. Covers CRUD, auth flows, authStore, realtime SSE, file handling, batch operations, and query syntax.
npm install pocketbase
# or
yarn add pocketbase
# or
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/pocketbase.umd.js"></script>
import PocketBase from 'pocketbase'
const pb = new PocketBase('http://127.0.0.1:8090')
const records = await pb.collection('posts').getList(1, 20, {
filter: 'status = "active" && created > "2024-01-01"',
sort: '-created,title',
expand: 'author,tags',
fields: 'id,title,author,created', // partial response
skipTotal: true, // skip COUNT query for better performance
})
// records.page, records.perPage, records.totalItems, records.totalPages, records.items
const allRecords = await pb.collection('posts').getFullList({
filter: 'status = "active"',
sort: '-created',
batch: 200, // records per request (default: 200)
})
const record = await pb.collection('posts').getOne('RECORD_ID', {
expand: 'author',
})
const record = await pb.collection('posts').getFirstListItem('slug = "my-post"', {
expand: 'author',
})
const record = await pb.collection('posts').create({
title: 'My Post',
body: 'Content here',
author: 'USER_ID',
status: 'draft',
})
const record = await pb.collection('posts').update('RECORD_ID', {
title: 'Updated Title',
status: 'published',
})
await pb.collection('posts').delete('RECORD_ID')
Same as API rules filter syntax. Common patterns:
// Equality