Replication

By default, we are going to run into CORS (Cross Origin Resource Sharing) issues when trying to interact with CouchDB. You may get an error like this:

XMLHttpRequest cannot load http://localhost:5984/employee/?_nonce=1466856096255. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

To fix this, you can simply install the add-cors-to-couchdb package.
Run the following command:

npm install -g add-cors-to-couchdb

Then run the following command with CouchDB up and running :

add-cors-to-couchdb

If it worked, you should get a message saying “Success”. This will configure CouchDB correctly, and you only ever need to run this once.
Now add following code to createPouchDB() in EmployeeProvider :

  this.remote = 'http://localhost:5984/employees';

  let options = {
    live: true,
    retry: true,
    continuous: true
  };

  this.pdb.sync(this.remote, options);

This sets up live (or continuous) bi-directional syncronisation of the PouchDB with CoudchBD.
If you need more options or other configurations, have a look at : https://pouchdb.com/guides/replication.html

For the fully working example, click here