· 6 years ago · Oct 12, 2019, 11:32 PM
1'use strict'
2const StreamrClient = require('streamr-client');
3const apiKey = '' // read-only key created via streamr.network/stream
4
5// Create the client using api key
6const client = new StreamrClient({
7 auth: {
8 apiKey: apiKey
9 }
10})
11
12// subscribe to receive messages published by other clients
13var count = 0;
14console.log(`stop feteching stream after there are 5 data (or press CTRL-C)...`)
15const sub = client.subscribe(
16 {
17 stream: '31lQzneQQwicPuy_obROdg', // test stream
18 resend: {
19 last: 5
20 }
21 },
22 // The "message" variable includes the "content" plus other metadata information
23 (content, message) => {
24 console.log(content)
25 count += 1;
26 if (count >= 5) client.unsubscribe(sub);
27 }
28)