Use proxy with Undici Fetch request in Node JS

Viewed 37

Question

I'm unsure about how to use a proxy with Undici fetch. I hope to use separate proxies for any fetch request with username and password authentication if applicable. I've found some documentation for proxies, but I haven't seen much about using proxies with the fetch api.

Solution

As for a good solution I'd hope for a code example to perform a simple get request to a site (e.g. to ifconfig.me) using a proxy and instructions on how to include a username and password with that proxy.

The solution should do the same function as the code below but using a proxy:

const { fetch } = require("undici");

const req = await fetch('https://ifconfig.me/all');
const res = await req.text();
Node version 18 is being used.
0 Answers
Related