{"library":"pocketbase","title":"PocketBase JavaScript SDK","description":"The PocketBase JavaScript SDK is the official client library for interacting with the PocketBase API, supporting both browser and Node.js environments. It provides comprehensive functionalities for data management, user authentication (including password and OAuth2 flows), and real-time subscriptions. The current stable version is 0.26.8, with the project maintaining a frequent release cadence to deliver bug fixes, performance improvements, and feature parity with the core PocketBase server. Key differentiators include its seamless integration with the PocketBase ecosystem, robust type definitions, flexible authentication store options (e.g., `LocalAuthStore` for web, `AsyncAuthStore` for React Native), and a crucial `pb.filter()` helper for securely binding filter parameters to prevent string injection attacks when handling untrusted server-side input.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install pocketbase"],"cli":null},"imports":["import PocketBase from 'pocketbase';","const PocketBase = require('pocketbase/cjs');","import { EventSource } from 'eventsource'; global.EventSource = EventSource;"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import PocketBase from 'pocketbase';\nimport 'cross-fetch/polyfill'; // Only for Node < 17\n\nconst pb = new PocketBase('http://127.0.0.1:8090');\n\nasync function initializeApp() {\n  try {\n    // Example: Authenticate as an auth collection record\n    const userData = await pb.collection('users').authWithPassword('test@example.com', '123456');\n    console.log('User authenticated:', userData.record.email);\n\n    // Example: List and filter 'posts' collection records\n    const result = await pb.collection('posts').getList(1, 20, {\n      filter: pb.filter('status = true && created > {:date}', { date: new Date('2023-01-01T00:00:00Z') }),\n      sort: '-created'\n    });\n    console.log('Posts found:', result.items.length);\n\n    // Example: Create a new record\n    const newPost = await pb.collection('posts').create({\n      title: 'My new post',\n      content: 'This is some content.',\n      status: true,\n      author: userData.record.id\n    });\n    console.log('New post created:', newPost.id);\n\n  } catch (error) {\n    console.error('An error occurred:', error);\n    if (error.isAbort) {\n        console.error('Request was aborted.');\n    }\n  }\n}\n\ninitializeApp();","lang":"typescript","description":"Demonstrates initializing the PocketBase client, authenticating a user, fetching and filtering records, and creating a new record. Includes necessary polyfills for Node.js compatibility.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}