Getting Started with PouchDB to Replace Parse

Feb 22, 2016

With the demise of Parse, I had to be receptive to alternatives. Luckily I had already been suggested a contender, PouchDB. Theoretically, the first thing needed is to create a JSON payload with some important data you need to replicate from the client.

Now, where is this data going to be stored?

If you are already using indexedDB for client-side storage of JSON documents, PouchDB could make storing that data on the server a whole lot simpler.

Even for strictly local development, the system seems quite useful.


CAP theorem, named after the three guarantees that are supposed to be impossible to achieve simultaneously in distributed systems, can help show where mongoDB and CouchDB differ.

Practically this means the PouchDB/CouchDB is updated in a more distributed, eventually consistent manner. Whereas MongoDB has a central node that coordinates all reads and writes to the secondary stores.

So what is PouchDB? It’s an in-browser database, with the same API as CouchDB, but as suggested by the name, a portable version. Even npm runs using CouchDB. But that was a relatively recent 2014.

It uses a REST like API. So mainly you will be using GET, PUT, POST, HEAD, DELETE to interact with your data.

Now to get started with your project:

npm init

npm i pouchdb —save

then require,


 PouchDB = require('pouchdb');


 db = new PouchDB('Local_database');

A unique _id property is necessary on each object. Any new data set on objects with the same _id property will merely update that object.

First set up the listener and add data. Listen for changes on the db object:


since: 'now',

live: true

}).on('change', showData);

Add the data to the db object:




data = {


title: title,

completed: false




cb(err, result){





('error: ', err);




Once you put some JSON data into the pouch db instance, to retrieve that data just use an accessor method on the db instance, like allDocs.




{include_docs: true, descending: true},


(err, doc) {



Now that you have verified that data has been added, sync the data with something you need at least a local pouchDB database and a remote couchDB database.

To test syncing you need to have setup CouchDB. From the Futon admin interface, the data can be seen syncing.


To replicate a PouchDB you need a CouchDB instance. you can download it from .

or use .




Couched needs to be CORS enabled.

The methods GET, PUT, POST, HEAD, DELETE need to be added in the core config.

You can go to http://localhost:5984/_utils/config.html add a new section then set credentials to true;

headers to accept, authorization, content-type, origin, referer;

methods to GET, PUT, POST, HEAD, DELETE;


origins to * .

Lastly make sure the config key the httpd is set to true for the enable_cors option.

Now that CouchDB is setup you try syncing



CouchDB_URI = 'http://localhost:5984/pouch';







and what you get is:

Another benefit of using pouchDB for files is that it can handle images and store them to blob for you as well as syncing it.

Lastly, if you were worried about migrations, don’t. New versions of PouchDB auto migrate so that your PouchDB can be accessed from the new version of PouchDB.

With pouchdb syncing data becomes quite simple. It’s just a matter of locating the path to your remote db and the name of the local db. Then it just 2 replicate calls away from syncing the data which you can bypass with a single sync call.




Building an AI Policy for Your Company

Building an AI Policy for Your Company

Artificial Intelligence (AI) is an integral part of our present-day technology landscape. At Sourcetoad, we’ve been assisting our clients for years in leveraging this powerful tool. However, it’s become more important than ever to have an internal policy on how these...

Sourcetoad Presents: Fine-Tuning OpenAI

Sourcetoad Presents: Fine-Tuning OpenAI

Welcome to Sourcetoad’s first video in our Artificial Intelligence series! In this video, Sourcetoad’s own AI subject matter experts discuss how to fine-tune OpenAI. After watching this presentation, you’ll learn: ✅ What fine-tuning means✅ How to use fine-tuning to...

The Agile Manifesto in Practice: Part 2

The Agile Manifesto in Practice: Part 2

The Agile approach to software development first emerged in response to the inflexibility of existing project management methodologies. Unlike traditional approaches that emphasize extensive documentation at every phase of development, Agile instead values the...