In Express, streaming responses are easy to implement since res
is a stream object.
Inside a Feathers custom service method, however, how can I stream something as a response?
In Express, streaming responses are easy to implement since res
is a stream object.
Inside a Feathers custom service method, however, how can I stream something as a response?
You might be able to implement a custom response format which pipes res.data
if it is a stream, and then resolve your service method with a stream. There is also a discussion about streaming data here.
You can add a custom service middleware before or after a specific service, and then you can use res
.
Example:
const todoService = {
async get(id) {
return {
id,
description: `You have to do ${id}!`
};
}
};
function streamResponse(req, res, next) {
res.write('Streams are awesome!');
res.end;
}
app.use('/todos', todoService, streamResponse);