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.




The Agile Manifesto in Practice: Part 1

The Agile Manifesto in Practice: Part 1

  How Sourcetoad Values People Over Process The software development process can involve a lot of uncertainty for both development teams and clients alike, especially in the early phases of a project. How can the long-term vision of an application be balanced...

What to Consider When Building HIPAA-Compliant Software

What to Consider When Building HIPAA-Compliant Software

In 1999, the Department of Health and Human Services (HHS) passed the Health Insurance Portability and Accountability Act (HIPAA) as a measure to protect personal health information (PHI) and allow people control of their healthcare records. The HITECH Act was enacted...

The Evolution of Buy Now, Pay Later in eCommerce: Part 2

The Evolution of Buy Now, Pay Later in eCommerce: Part 2

In Part 1, we talked about the rapid growth of Buy Now, Pay Later (BNPL) and discussed its expansion across industries. In Part 2, we will consider how impending regulation may shake up the short-term lending space.   Impending Regulation of BNPL While consumers...