I want to send data using the stream in nodejs. I tried to send the data using pipe but it didn't work, please help me out.
const { Readable } = require("stream")
app.get('/test', async (req, res) => {
let month = ['jan','feb','mar','apr','may','jun','jul'];
let stream = new Readable({read(size){}});
stream.setEncoding('utf8')
for (let m of month) {
stream.push(m)
}
stream.on('data', (data) => {
console.log(data)
res.write(data,'utf8')
})
stream.on('end',() => {
res.end();
})
})
I also tried this but did not work...
const { Readable } = require("stream")
app.get('/test', async (req,res) => {
let month = ['jan','feb','mar','apr','may','jun','jul'];
let stream = new Readable({read(size){}});
stream.setEncoding('utf8')
for (let m of month) {
stream.push(m)
}
stream.pipe(res)
})