Friday, 19 July 2019

Receiving streamed data in Express sent from controller

I've been following the instructions in an article I found here, and while I've managed to get it working in the controller, I don't know how to stream the data to the route that called it.I'm struggling with this because I don't know what questions to ask, and the articles I find on streaming are for files and not data.So, the controller is:services.buildIndices = async (params) => { const createCounterReader = (delay) => { let counter = 0; const reader = new Readable({ objectMode: true, read() {}, }); setInterval(() => { counter += 1; console.log('reading:', counter); reader.push(counter); }, delay); return reader; }; const counterReader = createCounterReader(1000); const logWriter = new Writable({ objectMode: true, write: (chunk, _, done) => { console.log('writing:', chunk); done(); }, }); return counterReader.pipe(logWriter); } ... and the route is:router.get('/elastic/indices/:typeOfAsset/build', async (req, res) => { const buildIndices = await controllerElastic.buildIndices(req.params); res.json(buildIndices) }) What would I need to do to get the controller to stream the count into the route, which in turn passes the stream onto the component in Vue?

Submitted July 19, 2019 at 10:05AM by WayneSmallman

No comments:

Post a Comment