From 2b89b9148b01b3c5920aa3506cc546af85031d3a Mon Sep 17 00:00:00 2001 From: Ivan Zvonimir Horvat Date: Mon, 23 Oct 2023 00:09:39 +0200 Subject: [PATCH] 32: README; add koa+koa router usage example --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 1489805..db8ee13 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,16 @@ app.get('/api/users', (req, res, next) => { }); ``` +## Practical Example with Koa + Koa Router + Mongoose + +```javascript +app.get('/api/users', (ctx) => { + ctx.type = 'json'; // Required for proper handling by test frameworks and some clients + ctx.body = new JsonStreamStringify(Users.find().stream()); +}); +``` + + ### Why do I not get proper typings? (Missing .on(...), etc.) install ``@types/readable-stream`` or ``@types/node`` or create your own ``stream.d.ts`` that exports a ``Readable`` class.