Pipe a stream to nowhere

Viewed 886

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.

2 Answers

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.

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")).
Related