Error "getaddrinfo ENOTFOUND" When Using node-auth0 ManagementClient
When using the node-auth0 SDK's ManagementClient to make requests to the Auth0 Management API, the following generic error message may be encountered:
FetchError: The request failed and the interceptors did not return an alternative response
The full error log is:
FetchError: The request failed and the interceptors did not return an alternative response
at BaseAPI.fetch (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:84:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async OAuth.request (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:115:26)
... 4 lines matching cause stack trace ...
at async ClientsManager.request (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:115:26)
at async ClientsManager.getAll (<REDACTED>/node_modules/auth0/dist/cjs/management/__generated/managers/clients-manager.js:97:26)
at async runLookup (<REDACTED>/app.js:29:17) {
cause: TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11118:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BaseAPI.fetchWithTimeout (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:34:24)
at async BaseAPI.fetch (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:66:27)
at async OAuth.request (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:115:26)
at async grant (<REDACTED>/node_modules/auth0/dist/cjs/auth/base-auth-api.js:84:22)
at async TokenProvider.getAccessToken (<REDACTED>/node_modules/auth0/dist/cjs/management/token-provider.js:20:85)
at async TokenProviderMiddleware.pre (<REDACTED>/node_modules/auth0/dist/cjs/management/token-provider-middleware.js:26:23)
at async BaseAPI.fetch (/<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:52:26)
at async ClientsManager.request (<REDACTED>/node_modules/auth0/dist/cjs/lib/runtime.js:115:26) {
cause: Error: getaddrinfo ENOTFOUND https
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'https'
}
}
}
Inspecting the detailed error output reveals a more specific underlying cause related to a DNS lookup failure:
cause: Error: getaddrinfo ENOTFOUND https
or
cause: Error: getaddrinfo ENOTFOUND undefined
This indicates that the Node.js runtime was unable to resolve the hostname provided for the API request.
- node-auth0 ManagementClient
The getaddrinfo ENOTFOUND error occurs at the Node.js HTTP layer when a domain name cannot be resolved via DNS. In the context of the node-auth0 SDK, this is typically caused by improper initialization of the ManagementClient. The two most common reasons are:
-
Including the protocol (
https://) in thedomainstring. The SDK expects only the fully qualified domain name (e.g., <tenant>.us.auth0.com). It handles adding thehttps://protocol internally. Providing the protocol prefix results in an attempt to resolve an invalid hostname likehttps://<tenant>.us.auth0.com, which fails. -
The
domainparameter value isundefined. This can happen if the domain is loaded from an environment variable that is not set, causing the SDK to make a request to an undefined host.
To resolve this issue, verify that the domain parameter provided when initializing the ManagementClient is a valid Auth0 domain without the protocol prefix and is not undefined.
Always follow the initialization patterns described in the official Management API Client documentation.
Correct Initialization Examples
Below are the correct ways to initialize the client, either with Client Credentials or a pre-obtained API token.
1. Initialize with Client ID and Client Secret
import { ManagementClient } from 'auth0';
var management = new ManagementClient({
domain: '{YOUR_TENANT_AND REGION}.auth0.com',
clientId: '{YOUR_CLIENT_ID}',
clientSecret: '{YOUR_CLIENT_SECRET}',
});
Note: If using environment variables (e.g., process.env.AUTH0_DOMAIN), double-check that the variable is correctly loaded and does not include the https:// prefix.
2. Initialize with an API v2 Token
Similarly, when using a token, the domain must be formatted correctly.
import { ManagementClient } from 'auth0';
var management = new ManagementClient({
domain: '{YOUR_TENANT_AND REGION}.auth0.com',
token: '{YOUR_API_V2_TOKEN}',
});
By providing the correct hostname for the domain parameter, the SDK can construct a valid request URL, allowing the underlying HTTP client to resolve the domain and successfully connect to the Auth0 Management API.