-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (30 loc) · 889 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var couchUrl = 'http://localhost:5985'
var nano = require('nano')(couchUrl)
nano.db.create('test', function (error) {
if (error && error.statusCode !== 412) return console.log(error)
console.log('fixing admin party')
nano.request({
method: 'put',
path: '_config/admins/admin',
body: 'secret'
}, function(error) {
if (error) {
return console.log(error)
}
// open this URL to get the same result
// http://localhost:5985/test/_changes?since=0&feed=continuous&heartbeat=30000
console.log('listen to changes for /test')
var db = nano.use('test')
var feed = db.follow({})
feed.on('change', function(change) {
console.log('change detected:\n%j', change)
})
feed.follow()
process.nextTick(function() {
db.insert({test: 1})
})
setTimeout(function() {
db.insert({test: 2})
}, 1000)
});
})