#Stream of newline-delimited JSON chunk

1 messages · Page 1 of 1 (latest)

white bolt
#

Hello! I need to send to my NestJS server a stream.

Request to my server:

  const req = request(
      `${appService}/process-payments`,
      {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
      },
      (res) => {
        console.log(`STATUS: ${res.statusCode}`);
        res.on('data', (chunk) => {
          console.log(`Body: ${chunk}`);
        });
        res.on('end', () => {
          console.log('No more data in response.');
        });
      }
    );

 stream.pipe(req);
// then in a loop I do the following:
 stream.write(data + '\n');
// after the loop
stream.end();

my controller method:

  @Post('process-payments')
  async processPayments(@Req() stream: Readable): Promise<void> {
    console.log('here.');
    stream.on('data', (data) => {
      console.log(data);
    });
  }

and I got:
Body: {"message":"Unexpected token { in JSON at position 32","error":"Bad Request","statusCode":400}

I also tried to disable bodyParser or use rawBody, but I have not succeeded.

white bolt
#

I am able to receive buffer if I set bodyParser: false, but I need this bodyParser for rest of my application. So how can I disable it only for a certain method handler?