DEV Community

Alex Spinov
Alex Spinov

Posted on

PocketBase Has a Free Backend-in-a-File That Replaces Firebase

Firebase is convenient until the bill arrives. Supabase is great but needs a server. PocketBase gives you a complete backend in a single binary file — database, auth, file storage, real-time subscriptions, and an admin UI.

One File. Entire Backend.

# Download (8MB binary)
wget https://github.com/pocketbase/pocketbase/releases/latest/download/pocketbase_linux_amd64.zip
unzip pocketbase_linux_amd64.zip

# Run
./pocketbase serve
# Admin UI: http://127.0.0.1:8090/_/
# API: http://127.0.0.1:8090/api/
Enter fullscreen mode Exit fullscreen mode

That is your entire backend. SQLite database, REST API, admin dashboard — everything.

What You Get

1. Database (Collections = Tables)

Create collections via the admin UI or API. PocketBase auto-generates REST endpoints:

GET    /api/collections/posts/records     → List posts
POST   /api/collections/posts/records     → Create post
GET    /api/collections/posts/records/:id  → Get post
PATCH  /api/collections/posts/records/:id  → Update post
DELETE /api/collections/posts/records/:id  → Delete post
Enter fullscreen mode Exit fullscreen mode

2. Authentication (Built-in)

import PocketBase from "pocketbase";

const pb = new PocketBase("http://127.0.0.1:8090");

// Email/password auth
await pb.collection("users").authWithPassword("user@example.com", "password");

// OAuth2 (Google, GitHub, Discord, etc.)
await pb.collection("users").authWithOAuth2({ provider: "google" });

// Check auth state
if (pb.authStore.isValid) {
  console.log(pb.authStore.record.email);
}
Enter fullscreen mode Exit fullscreen mode

3. Real-Time Subscriptions

// Subscribe to changes on the "posts" collection
pb.collection("posts").subscribe("*", (e) => {
  console.log(e.action); // "create", "update", "delete"
  console.log(e.record);
});

// Subscribe to a specific record
pb.collection("posts").subscribe("RECORD_ID", (e) => {
  console.log("Post updated:", e.record);
});
Enter fullscreen mode Exit fullscreen mode

4. File Storage

const formData = new FormData();
formData.append("title", "My Post");
formData.append("image", fileInput.files[0]);

const record = await pb.collection("posts").create(formData);
// File URL: pb.files.getURL(record, record.image)
Enter fullscreen mode Exit fullscreen mode

5. API Rules (Row-Level Security)

Set rules per collection in the admin UI:

List rule:   @request.auth.id != ""
View rule:   @request.auth.id != ""
Create rule: @request.auth.id != ""
Update rule: @request.auth.id = author.id
Delete rule: @request.auth.id = author.id
Enter fullscreen mode Exit fullscreen mode

Extend with Go or JavaScript

// pb_hooks/main.pb.js
routeAdd("GET", "/api/custom/stats", (e) => {
  const total = $app.countRecords("posts");
  return e.json(200, { total });
});

onRecordCreate((e) => {
  // Send notification, update analytics, etc.
  console.log("New post:", e.record.get("title"));
  e.next();
}, "posts");
Enter fullscreen mode Exit fullscreen mode

PocketBase vs Firebase vs Supabase

Feature Firebase Supabase PocketBase
Self-hosted No Yes (complex) Yes (1 file)
Database NoSQL PostgreSQL SQLite
Auth Yes Yes Yes
File storage Yes Yes Yes
Real-time Yes Yes Yes
Admin UI Console Dashboard Built-in
Free tier limits Strict Generous Unlimited
Deployment Cloud only Docker (heavy) Single binary

Deploy Anywhere

# Fly.io (free tier)
fly launch --image pocketbase/pocketbase

# Any VPS
scp pocketbase user@server:~/
ssh user@server "./pocketbase serve --http 0.0.0.0:8090"

# Docker
docker run -p 8090:8090 -v ./pb_data:/pb/pb_data pocketbase/pocketbase
Enter fullscreen mode Exit fullscreen mode

Need a custom backend or data extraction solution? I build APIs and web scraping tools. Email spinov001@gmail.com or check my developer tools on Apify.

Top comments (0)