PouchDB is an awesome little library that lets you replicate your local database to other remote databases like CouchDB. Because of Access-control-allow-origin, setting up a locally hosted project isn’t immediately obvious. I’ll give a walkthrough on how to setup PouchDB with CouchDB in the simplest terms possible.
sudo -i -u root couchdb -b
Or for windows go to the CouchDB/bin folder and run couchdb.bat
And you should see a welcoming message telling you that it’s time to relax (it’s not time to relax yet). Once you get CouchDB setup, you’ll need a CORS proxy to allow access to your CouchDB database from a different domain. The easiest and simplest one I found is a node package called corsproxy. Simply run:
npm install -g corsproxy
And now you have your corsproxy. Run it by typing
Pouch.replicate('idb://myapp', 'http://localhost:5984/myapp', myCallback)
'idb://myapp' is your local database and
'http://localhost:5984' is your CouchDB database. However since your app is being hosted on a different port you will get a Access-control-allow-origin error. Change that remote database to now point to the corsproxy you setup which has a default port of 9292:
Pouch.replicate('idb://myapp', 'http://localhost:9292/localhost:5984/myapp', myCallback)
Kazam! There you go, replicating PouchDB to/from a remote CouchDB! Now it’s time to relax.