Skip to content

Server Hooks Overview (.pb.js)

Server hooks (pb_hooks/*.pb.js) allow you to intercept database lifecycle events, define custom API endpoints, and execute server-side business logic in JavaScript or Go.

Pocket Kit provides a visual In-Dashboard Hook Studio, 1-Click Recipe Marketplace, and Live Event Mocking & Tester to author and test backend logic with zero SSH or file transfer requirements.


🌟 Hook Studio Features

Interactive Code Studio

Write and edit .pb.js scripts with CodeMirror 6, TypeScript linting, and autocomplete directly in your browser.

1-Click Recipe Marketplace

Install pre-built templates for Stripe Webhooks, Discord Alerts, Resend Transactional Emails, and Telegram Bots.

Live Event Mocking & Dry Run

Simulate synthetic HTTP requests and database record events against your hooks in an isolated sandbox.

AST Security Sandbox

Automatic 4-step security pipeline blocking illegal system calls and verifying clean boot before deployment.


⚡ Quick Start: Intercepting Record Events

pb_hooks/posts.pb.js
onRecordCreate((e) => {
// Set default view count
e.record.set("views", 0);
// Proceed with create
e.next();
// Log event to instance stream
$app.logger().info("New post created: " + e.record.id);
}, "posts");

🌐 Adding Custom HTTP Endpoints

pb_hooks/custom_api.pb.js
routerAdd("GET", "/api/v1/stats", (e) => {
const totalPosts = $app.findRecordsByFilter("posts", "active = true").length;
return e.json(200, {
total_posts: totalPosts,
timestamp: new Date().toISOString(),
});
});