-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathv01.js
42 lines (34 loc) · 835 Bytes
/
v01.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
38
39
40
41
42
const Connection = require('ssb-client')
const pull = require('pull-stream')
console.log('Connecting')
Connection((err, server) => {
if (err) throw err
console.log('Connection established')
const opts = {
limit: 100,
reverse: true
}
pull(
server.query.read(opts),
pull.filter(msg => msg.value.content.type === 'post'),
pull.collect(onDone)
)
function onDone (err, msgs) {
if (err) {
console.error(err)
server.close()
return
}
msgs.forEach(msg => {
prettyPrint(msg)
console.log('------')
})
console.log(`${msgs.length} messages`)
server.close()
}
})
function prettyPrint (msg) {
console.log(JSON.stringify(msg, null, 2))
// this just print the full object out as a string that's been nicely indented
// with each level of nesting
}