PouchDB not syncing (Express set up)

113 views
Skip to first unread message
Message has been deleted

Alexandro Chen

unread,
Feb 16, 2016, 10:09:13 AM2/16/16
to PouchDB
The following code initiates two databases: db and remotedb. Then, then when router.get('/projects', function(req, res) is called both databases should sync:

var express = require('express')
var _ = require('lodash')
var PouchDB = require('pouchdb')
var webpack = require('webpack')
var config = require('./webpack.dev.conf')

var app = express()
var compiler = webpack(config)


var db = new PouchDB('vuedb')
var remotedb = new PouchDB('http://localhost:5984/vuedb')


// handle fallback for HTML5 history API
app
.use(require('connect-history-api-fallback')())


// serve webpack bundle output
app
.use(require('webpack-dev-middleware')(compiler, {
  publicPath
: config.output.publicPath,
  stats
: {
    colors
: true,
    chunks
: false
 
}
}))


// enable hot-reload and state-preserving
// compilation error display
app
.use(require('webpack-hot-middleware')(compiler))


// get an instance of the express Router
var router = express.Router()


// handle PouchDB stuff
router
.get('/projects', function(req, res) {
  console
.log('DB:', db)
  console
.log('REMOTE:', remotedb)

 
if (remotedb) {
    db
.sync(remotedb, {
      live
: true,
     
retry: true
   
}).on('changed', function (info) {
      console
.log('CHANGED', info)
   
}).on('error', function (err) {
      console
.log('ERROR', err)
   
})
 
}
})


// all of our routes will be prefixed with /api
app
.use('/api', router)


app
.listen(8080, 'localhost', function (err) {
 
if (err) {
    console
.log(err)
   
return
 
}
  console
.log('Listening at http://localhost:8080')
})

console.log('DB:', db) and console.log('REMOTE:', remotedb) do log the databases:

DB: PouchDB {
  _db_name
: 'vuedb',


REMOTE
: PouchDB {
  _db_name
: 'http://localhost:5984/vuedb',

However the databases don't sync, in fact, remotedb isn't created at all:


Why could be the cause? And how to fix it?

Alexandro Chen

unread,
Feb 16, 2016, 11:18:24 AM2/16/16
to PouchDB
**EDIT:**

PouchDB outputs this:

[info] GET
/vuedb/_changes?timeout=25000&style=all_docs&heartbeat=10000&since=0&limit=100
404 - 127.0.0.1
 
And this from time to time:
 
webpack: bundle is now VALID. (node) warning: possible EventEmitter
memory leak detected. 11 destroyed listeners added. Use
emitter.setMaxListeners() to increase limit. at PouchDB.addListener (events.js:239:17)
at PouchDB.once (events.js:265:8)
at new Changes$1 (/home/alex/node/project/node_modules/pouchdb/lib/index.js:703:6)


Maybe it reveals something?

Nolan Lawson

unread,
Mar 8, 2016, 12:04:48 PM3/8/16
to PouchDB
Did you ever figure this out? FWIW, pouchdb-server demonstrates how to get this working: https://github.com/pouchdb/pouchdb-server/blob/master/bin/pouchdb-server

Also in general I'd say I recommend just using pouchdb-server directly as a separate Node process instead of using express-pouchdb. Although it's nice to run everything in a single Node process, it's much more DIY than pouchdb-server is.
Reply all
Reply to author
Forward
0 new messages