简体   繁体   中英

Leaving node-fetch response without reading stream

Having the following code in a service (lets say on an express endpoint):

async function (res, req, next) {
  const fetch = require('node-fetch');

  await fetch('http://example.com/resource', { method: 'DELETE' });

  res.status(204).send();
}

What happens with the stream and connection opened by node-fetch ? Is it closed at some point? Or is it left open forever?

Is it better to do (await fetch(...args)).text() to consume the stream or its totally the same?

The connection is closed by itself, the stream is just the response.

You should read the stream to validate if you didn't have any errors on your delete

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM