5

I have a stream of data and I need to write it to nowhere, but without immediately stopping it. The code below writes to a file, so it keeps the connection alive for as long as the stream is going.

 request
.get(href)
.on('response', function(response) {
    console.log(response.statusCode)
    console.log(response.headers['content-type'])
})
.pipe(fs.createWriteStream("name.mp3"))

Is it possible to pipe that stream to nowhere, while still keeping the connection like fs.createWritableStream ?

I tried using dev-null (npm package), but it seems to just kill the connection immediately.

almarc
  • 1,598
  • 3
  • 11
  • 31

2 Answers2

4

Seems like a strange problem, but maybe you can use /dev/null, or the Windows equivalent explained in the post below?

How can I write to the NUL device under Windows from node.js?

I do see that you tried something similar with the dev-null package, but maybe try it without the package and see if that works.

Hein Andre Grønnestad
  • 6,885
  • 2
  • 31
  • 43
0

No package required, on linux (see almarc's comment on Hein's answer for Windows):

request
.get(href)
.on('response', function(response) {
    console.log(response.statusCode)
    console.log(response.headers['content-type'])
})
.pipe(fs.createWriteStream("/dev/null")).
Christian Fritz
  • 20,641
  • 3
  • 42
  • 71