require("reflect-metadata"); const { NestFactory } = require("@nestjs/core"); const { Controller, Module, Body, Post, Req } = require("@nestjs/common"); class C { @Post("/hook") hook(@Req() req, @Body() b) { return { rawBodyIsBuffer: Buffer.isBuffer(req.rawBody), rawBodyLen: req.rawBody ? req.rawBody.length : null, bodyKeys: b ? Object.keys(b) : null, bodyBlobLen: b && b.blob ? b.blob.length : null }; } } @Module({ controllers: [C] }) class M {} (async () => { const app = await NestFactory.create(M, { logger: false, rawBody: true }); const server = await app.listen(0); const port = server.address().port; const small = JSON.stringify({ hello: "world", n: 123 }); const r1 = await fetch(`http://127.0.0.1:${port}/hook`, { method: "POST", headers: { "content-type": "application/json" }, body: small }); console.log("small ->", r1.status, await r1.text()); const big = JSON.stringify({ blob: "x".repeat(150 * 1024) }); const r2 = await fetch(`http://127.0.0.1:${port}/hook`, { method: "POST", headers: { "content-type": "application/json" }, body: big }); console.log("150kb ->", r2.status, (await r2.text()).slice(0, 140)); await app.close(); })();