The actual answer is to why the options you're used to from the http
module aren't available is that perhaps surprisingly, node's builtin fetch()
global does not use the HTTP stack provided by the traditional builtin http
/https
modules.
Instead, it uses a parallel, from-scratch HTTP stack rewrite called undici.
Given that fetch()
's HTTP stack is entirely separate from the standard HTTP stack, it should not be surprising that the options you can supply to http.get
et al don't work with fetch()
.
undici's docs are available here. http Agent
s are replaced by a Dispatcher
. You can pass a custom Dispatcher
in to fetch(…, { dispatcher })
, which allows you to customize fetch
's HTTP behavior.
fetch()
built into nodejs that it is the identical API as what's in the browser? There are richer options such asgot()
oraxios()
ornode-fetch()
if you want support for node-specific behaviors. – Inflight