Request Relay · Level 2 of 7

The body comes in boxes

Watch when the POST body arrives compared to when the handler starts.

const http = require('node:http');const server = http.createServer((req, res) => {  let size = 0;  console.log('handler starts');  req.on('data', (chunk) => { size += chunk.length; });  req.on('end', () => {    console.log('body done: ' + size + ' bytes');    res.end('thanks');  });  console.log('handler returns');});server.listen(0, async () => {  const { port } = server.address();  const res = await fetch(`http://localhost:${port}`, { method: 'POST', body: 'hello world' });  console.log('client got ' + await res.text());  server.close();});

1. Predict the output

Tap the lines in the order you think they print.

  1. 1…
  2. 2…
  3. 3…
  4. 4…