1import{B as e,R as t,St as n,kt as r}from"./CzsObDY8.js";import"./xihTtKlq.js";import"./C5qy-xbg.js";var i=r({default:()=>l,metadata:()=>a}),a={title:`Extending PocketBase with JSVM`,description:`Learn how to extend PocketBase with JSVM, plugins, and server-side rendering using PocketPages`},{title:o,description:s}=a,c=e(`<h1>Programming and Extending PocketBase with JSVM</h1> <p>PocketBase is not just a simple backend solutionâit offers powerful capabilities for extending its functionality through JavaScript, specifically using the <strong>Goja engine</strong> and its <strong>JSVM</strong> (JavaScript Virtual Machine). This allows developers to add custom logic, plugins, and server-side rendering to their applications, making PocketBase a highly versatile platform.</p> <h2>A Growing Ecosystem</h2> <p>The <strong>PocketBase ecosystem</strong> is expanding rapidly, making it easier to enhance your applications in a modular and scalable way. A key project in this space is <strong><a href="https://pocketpages.dev" rel="nofollow">pocketpages.dev</a></strong>: a platform for building classic server-side rendered (SSR) pages with PocketBase. By leveraging PocketBaseâs <strong>JSVM</strong> and the Goja engine, developers can serve SSR content, delivering a seamless experience for static or dynamic web pages directly from PocketBase.</p> <h2>Extending PocketBase with JSVM</h2> <p>PocketBaseâs <strong>JSVM</strong> makes it possible to run custom JavaScript code directly within your PocketBase instance. This can be used for a wide range of tasks, from extending API functionality to adding business logic that runs server-side. With the JSVM feature, you can write JavaScript code that interacts with PocketBaseâs core services, hooks, and events.</p> <h3>Use Cases for JSVM</h3> <ul><li><p><strong>Custom API Routes</strong>: Use the JSVM to define and execute custom routes that go beyond the default PocketBase APIs. This enables more sophisticated data manipulation, custom validation, and complex business logic.</p></li> <li><p><strong>Hooks and Triggers</strong>: Integrate <strong>JavaScript hooks</strong> into your application to trigger actions in response to database changes, such as sending notifications when records are updated or applying complex validation before data is written.</p></li> <li><p><strong>Reusable Modules</strong>: Package custom logic as JavaScript modules in <code>pb_hooks</code> and share patterns across instances. The JSVM makes it straightforward to build reusable server-side code for PocketBase.</p></li></ul> <h2>Hosting Static and SSR Content</h2> <p><strong>PocketHost</strong> is an excellent choice for hosting both static/SSG (Static Site Generation) and SSR (Server-Side Rendered) content. With <strong>PocketPages.dev</strong> and similar technologies, you can combine the power of PocketBaseâs JSVM and server-side rendering to deliver fully dynamic web applications.</p> <ul><li><strong>Static Content</strong>: PocketHost supports static files and SSG, making it ideal for static websites or single-page applications.</li> <li><strong>Server-Side Rendering (SSR)</strong>: By using PocketPages and PocketBaseâs JavaScript capabilities, you can serve SSR pages directly from your backend. This provides the advantages of SEO and faster initial page loads for dynamic content.</li></ul>`,1);function l(e){var r=c();n(20),t(e,r)}export{l as n,i as t};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.