Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I start / stop a request stream with node.js?

I have

return request({
  method: "POST",
  url: response.stream.url,
  json: true,
  forever: true,
  body: {
    sessionid: response.stream.sessionid,
    symbols: symbolParams
  }
}).on("data", onData)

That gives me data whenever it comes through. But what if I want to STOP listening on that stream, how can I do that?

like image 901
Shamoon Avatar asked Dec 04 '22 22:12

Shamoon


1 Answers

It seems to implement Readable Stream interface, so pause() and resume() work.

const request = require('request');
const req = request('http://google.com')
  .on('data', data => { 
      console.log(data);  
      req.pause(); 
    });
like image 83
dsdenes Avatar answered Jan 05 '23 05:01

dsdenes