Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 5405

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 27, 20242024-11-27T08:55:08+00:00 2024-11-27T08:55:08+00:00

Pocketbase, readymade backend within clicks

  • 61k

As for a freelance developer his most works would be something like shopping cart, or content management services. However the task in the backend would be the database, file storage, and authentication management.

In each of his work he fixes almost the same problems, while some chooses services like firebase and supabase for database management and other common backend services. But the problem comes when these services are unaffordable as it's expensive or hard to configure.

Here in this short article introduces a new service, which would be a solution for this problem.

What's Pocketbase?

enter image description here
Pocketbase is an open source backend service, written in Go programming language, which enables a realtime database, file storage, authentication system, role and permission manager and email engine with an elegant admin ui dashboard to manage databases and other services.

Pocketbase supports javascript and dart SDKs officially in order to access the backend from the client side. This makes full stack development easier than ever, as the developer shouldn't be bothered with databases, role and permission management, realtime websockets and other backend services, as Pocketbase enables these all services within clicks.

Why Pocketbase.

Here are several reasons for preferring Pocketbase over other services like firebase and others.

  • Open source, so it is hostable in cloud services like vultr free of
    cost and customisable according to your use case.

    • Single file executable. So, it is easy to host on cloud instances, just start by running the executable file, nothing to configure.
    • Cross platform support. Supports Windows, Linux and Mac operating systems.
    • Statically build application. It’s built on top of GoLang, so it’s blazing fast and memory safe.So it would be better performing even on a basic $2.5 vultr instance_Pocketbase memory usage is about 12MB in Windows task manager. _
    • Easy to Integrate. Pocketbse officially provides Javascript and Dart Sdk which is helpful to integrate with flutter mobile apps and javascript frameworks like react and vue.

Quick start with Pocketbase.

Pocketbase is easy to get started within a few steps.

Step 1: Download and Unzip

you can download pocketbase for any of Linux, WIndows, Mac platforms from pocketbase.io documentation page. then unzip the downloaded zip with your favorite zip extractor.

Step 2: Run Pocketbase

You can run pocketbase using any console application. run console application in unzipped folder and run the command

./pocketbase serve 
Enter fullscreen mode Exit fullscreen mode

in Windows

pocketbase.exe serve 
Enter fullscreen mode Exit fullscreen mode

That's all to run a Pocketbase backend.

The console will print out the routes for the admin panel, static server and rest api server.

Go to the admin url (usually this would be : http://localhost:8090/)

First time you visit the admin panel you have to create an admin account. and you can open the admin account using these credentials.

Working with Pocketbase Collections.

You can create and manage database collections with the Pocketbase admin panel by clicking on create New Collection in the collection section.

This will open a drawer to define your database schema, here you can add fields for your collection in the field tab and role and permissions in the Api rules tab. After setting fields and api rules you can click the create button to create your collection.You can upload files by creating file field in collection fields,

Whenever you create a collection the collection would be displayed at the left corner as a button, by clicking the button you can add, edit, delete records to the collection.

Manage Users.

In order to create users and manage you can click on the users button. Users panel allows you to create, delete, edit users and their roles as admin and user. To create a user you have to provide the user email id and password , once you created a user Pocketbase send an verification mail to the email id to user verification.

In Pocketbase every user has a basic credential modal including email id and password, and a profile model which admin can customize them.

Working with web APIs.

Pocketbase officially supports Dart and Javascript SDKs, which would be helpful to integrate with mobile apps and web application frameworks, like Flutter, Vanilla Javascript, React and Vue. This tutorial will focus on Javascript SDK.

Step 1
Firstly you have to install Pocketbase npm package using the command
npm i pocketbase

Step 2
After the installation is completed you can import this into the frontend code. and connect with the server using the Pocketbase class.

import PocketBase from  'pocketbase';     const client =  new  PocketBase('http://127.0.0.1:8090'); 
Enter fullscreen mode Exit fullscreen mode

Step 3
Authenticate with your credentials, by logging in you would be allowed to access Pocketbase as the user permitted by admin.

const adminAuthData =  await client.admins.authViaEmail('test@example.com',  '123456'); 
Enter fullscreen mode Exit fullscreen mode

Pocketbase provides various types of authentication methods like google auth and other, refer the official docs for more details.

As you logged in you can access collections and all other services. For example you can list the collection records using Pocketbase.records.getList function

const pageResult =  await client.records.getList('demo',  1, 50,  { filter:  'created >= "2022-01-01 00:00:00"',}); 
Enter fullscreen mode Exit fullscreen mode

Refer the official doc for further details

Going to production

Pocketbase is self-hostable and easy to deploy, no configuration and no dependency is needed as it is completely portable, so it could deploy just by uploading and executing the file.

The example shown here is based on linux server,
Step 1
Firstly you have to allow Pocketbase ports in the server by the command

[root@dev ~]$ ufw allow 80  && ufw allow 443 
Enter fullscreen mode Exit fullscreen mode

Step 2

Then run the pocketbase executable file by the command

  [root@dev ~]$ ./pocketbase serve --http="yourdomain.com:80"  --https="yourdomain.com:443" 
Enter fullscreen mode Exit fullscreen mode

Pocketbase server will run on “yourdomain.com”

Adding into Service

Instead of using previous method, you have to add Pocketbase into service. By adding into service the server would be active after you restart your server. in order to add into service you have to create a service file namely pocketbase.service and edit the file as shown below.

[Unit]  Description = pocketbase    [Service]  Type = simple  User =  YOUR_USER  Group =  YOUR_GROUP  LimitNOFILE =  4096  Restart = always  RestartSec = 5s  StandardOutput = append:/your/path/to/logs/errors.log  StandardError = append:/your/path/to/logs/errors.log  ExecStart =  /your/path/to/pocketbase serve --http="yourdomain.com:80"  --https="yourdomain.com:443"    [Install]  WantedBy = multi-user.target 
Enter fullscreen mode Exit fullscreen mode

Save the file and run the command

[root@dev ~]$ systemctl enable pocketbase.service  [root@dev ~]$ systemctl start pocketbase 
Enter fullscreen mode Exit fullscreen mode

These commands add pocketbase into service, though pocketbase will restart when your server restarts.

Serve static files with pocketbase

You can serve static files like html, css, using pocketbase.

In order to enable static serving you have to create a folder named ‘pb_public’ in the pocketbase base directory and copy files to the pb_public . The static files would be served in the base pocketbase url ( usually in http://localhost:8090/)

fullstackgojavascriptwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.