I have a function that returns a stream and I want to pipe that value to another function then return it in an Express response like so:
const { Duplex } = require('stream');
const request = require('request;);
const example = async function getRequest() {
return request({ blah }).pipe(Duplex);
};
const secondExample = async function getRequestSecond() {
return example().pipe(Duplex);
};
router.get('/', async (req, res) => {
return secondExample().pipe(res);
});
These functions all sit in different classes, but the general idea is the same. My understanding of Streams leads me to believe that piping the data to a Duplex stream and returning that should allow me to pipe it all the way down to the response, but at the secondExmaple
function and in the router.get
function I start to get TypeError: secondExample(...).pipe is not a function
and I'm not understanding why.