I'm just trying to understand the node stream and trying to create a pipe. so reading a file and writing to another writeable stream and again passing to res since that is also the writeable stream.
But it throws the error
Error [ERR_STREAM_CANNOT_PIPE]: Cannot pipe, not readable
Please let me know the reason of the failure and also have a look on below code for intel.
const http = require('http')
const fs = require('fs')
var server = http.createServer((req, res)=>{
//created the read strem
let file = fs.createReadStream('./temp_files/file1.txt')
// pipig this RES, since is RES is the aother writeable stream
let des = fs.createWriteStream('./temp_files/final.tct')
file.pipe(des).pipe(res) // ERROR <<<------------------------------
})
server.listen(9090, (req, res)=>{
console.log("runnig at port 9090")
})
You cannot chain pipe calls with both writable streams. You need to have a duplex stream in the middle.
So replace file.pipe(des).pipe(res) you can try the following:
file.pipe(des);
file.pipe(res);
Since des is not a transform stream they can work independently and shouldn't make any difference.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.