PocketBase is an open-source backend consisting of an embedded SQLite database with data validation, real-time subscriptions, and an easy-to-use REST API. It also offers authentication and file storage for media files.

PocketBase is perfect for projects you’d rather not build a backend for either because of time constraints or convenience because it’s completely portable and requires minimal setup. It also integrates with popular technologies like Vue, Svelte, React, Angular, and Flutter.

Services Provided by PocketBase

PocketBase provides most of the services offered by other backend providers like SupaBase.

  • SQLite database: PocketBase includes an embedded SQLite database. This differs from other backend providers that use larger databases like PostgreSQL or MySQL. The use of SQLite makes PocketBase more lightweight. You can also subscribe to real-time database events through an API.
  • Authentication: PocketBase supports email/password authentication, and OAuth2 authentication via Facebook, Google, GitLab, and GitHub.
  • File storage: You can upload photos, audio, and video files to local storage or an S3 bucket using PocketBase.
  • Admin dashboard: The Admin dashboard lets you create and manage collections in the database. You can also upload files, view log files, and configure the setting for sending emails,

According to the docs, PocketBase can serve easily serve 10,000+ concurrent and persistent real-time connections on 6 virtual private servers making it an affordable backend choice for small to medium applications.

Note that PocketBase only scales vertically. This means you need to add more CPU and RAM to increase the processing power. If you have a large application, consider a backend provider like Firebase that allows horizontal scaling.

Getting Started With PocketBase

Currently, PocketBase provides two SDKs:

  • A JavaScript SDK that you can use with JavaScript frameworks like Svelte, React, Vue, and Angular.
  • A Dart SDK for Flutter apps.

The easiest way to get started is to download PocketBase. There are several links, so make sure to download the one compatible with your environment.

Once you’ve downloaded it, extract and navigate to the pocketbase folder. Then run this command in a terminal:

        ./pocketbase serve

This command should start a web server at these routes.

  • Server: http://127.0.0.1:8090/
  • REST API: http://127.0.0.1:8090/api/
  • Admin UI: http://127.0.0.1:8090/_/

Navigate to the http://127.0.0.1:8090/_/ URL to create your first collection using the admin dashboard.

Creating a Collection in PocketBase

The first time you open the admin UI, it will ask for an email address and password to create an admin account.

Here is what the admin UI looks like:

Pocketbase admin UI

Clicking the New collection button in the admin UI will open a collection panel you can fill in with details to create a new collection.

Here’s how you’d create a collection called todos consisting of a title and completed fields:

Todo pocketbase collection

A collection can either be a base or auth collection. A base collection is the default collection type and you can use it for any type of data. An auth collection contains extra fields to manage users, like username, email, and verified.

You don’t need to use the admin UI to create a collection; you can create one using the Web API. PocketBase docs provide SDK-specific examples of how to create and manage collections via the API. You can create, view, update, delete, or import collections.

Using PocketBase in a React Application

The JavaScript SDK allows you to interact with PocketBase from a React project.

To follow along, start by creating a React project.

Then, install the PocketBase JavaScript SDK in your React project via npm:

        npm install pocketbase --save

Next, in app.js, import PocketBase and initialize it.

        import PocketBase from 'pocketbase';
const pb = new PocketBase('http://127.0.0.1:8090');

To illustrate how PocketBase integrates React, you’ll create the helper functions for a to-do application. These functions will create, update, retrieve, and delete items.

Create a Todo Item

In app.js, create a function called addTodo.

        const addTodo = async (todo) => {
 try {
   const record = await await pb.collection("todos").create(todo);
   return record;
 } catch (error) {
   return { error: error.message };
 }
};

This function adds a new record in the todos collection.

Update a Todo Item

To update a record in the todo collection, create a function called updateTodo and use the update method.

        const updateTodo = async (record_id, todo) => {
 try {
   const record = await pb.collection("todos").update(record_id, todo);
   return record;
 } catch (error) {
   return { error: error.message };
 }
};

The updateTodo function finds the to-do item based on the record Id and updates it with the new data.

Delete a Todo Item

In app.js, create a function called deleteTodo that deletes a record in the todo collection.

        const deleteTodo = async (record_id) => {
 try {
   await pb.collection("todos").delete(record_id);
 } catch (error) {
   return { error: error.message };
 }
};

Retrieve a Todo Item

You can retrieve a single to-do item or all the items from the collection.

This function retrieves a single to-do item by id:

        const getTodo = async (record_id) => {
 try {
   const record = await pb.collection("todos").getOne(record_id, {
     expand: "relField1,relField2.subRelField",
   });
   return record
 } catch (error) {
   return { error: error.message };
 }
};

While the function below will retrieve all the records in the todo collection:

        const getTodos = async (record_id) => {
  try {
    const records = await pb
      .collection("todos")
      .getFullList(200 /* batch size */, {
        sort: "-created",
      });
    return records;
  } catch (error) {
    return { error: error.message };
  }
}

You can use these functions to create and update the application's UI.

For more detailed examples, see the PocketBase records API documentation or the generated API documentation in the "Admin UI > Collections > API Preview". You should be able to access list, view, create, update, delete, and the real-time documentation for your collection.

generated api docs

Why You Should Use PocketBase

PocketBase is the best backend for small to medium projects. It requires minimal setup and is easy to use. It offers two client SDKs—a JavaScript SDK and a Dart SDK—and you can use it in web and mobile applications.

PocketBase is also self-hostable, and you can host it on a local server or a VPS. While it doesn’t support cloud functions, you can use it as a Go framework and create your own app with custom business logic.