DNS
resolver.setServers()
Configures a dedicated Resolver instance without changing the process-wide resolver. Do not accept untrusted DNS server settings. This example sends no packets. Tested on Node.js 22.16.0. Example output (one line per entry): ["127.0.0.1:53535"].
Formal Syntax & Structure
nodejs syntaxnodejs
resolver.setServers(servers)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| servers | string[] | Resolver server addresses and optional ports. |
Return Value
undefined
Updates the instance.
Working Example
Example Snippetnodejs
import { Resolver } from 'node:dns/promises';const r = new Resolver();r.setServers(['127.0.0.1:53535']);console.log(r.getServers().join(','));