The DNS NOTFOUND error occurs when a DNS server responds to a query but contains no answer records for the requested domain. This indicates the domain doesn't exist, is improperly configured, or the DNS server lacks the record information. This is different from timeouts or unreachable servers.
The NOTFOUND error in Node.js DNS operations indicates that a DNS query was successfully sent to and received by the DNS server, but the response contained no answer section. In other words, the DNS server performed the lookup and definitively answered: "I don't have a record for that domain." This differs from ENOTFOUND errors which occur when the DNS server doesn't respond at all. With NOTFOUND, the DNS infrastructure is working—the server is reachable and responding—but it cannot provide the requested record. The "no answers section" phrase means the DNS response packet structure is valid but the answer section (the part containing the requested A, AAAA, MX, or other records) is empty. This happens when: - The domain genuinely doesn't exist - The domain exists but has no records of the type you requested - DNS propagation is incomplete or misconfigured - The DNS server is authoritative but lacks the record information
First, confirm the domain is real and reachable:
# Check if domain is accessible
curl -I https://example.com
# Or try to ping it
ping example.com
# Check domain registration
whois example.comIf the domain is accessible in a browser or via curl, but Node.js cannot resolve it, the issue is DNS-specific.
Use dig to see what the DNS server is actually returning:
# Query A records
dig example.com A
# Query AAAA records (IPv6)
dig example.com AAAA
# Query with a specific DNS server
dig @8.8.8.8 example.com
# Get verbose output showing the answer section
dig +noall +answer example.comIf the answer section is empty, the DNS server has no records for that domain. Check if you're querying the correct record type or if the domain configuration is incomplete.
New domains or recently changed DNS records may not have propagated globally:
# Check DNS propagation using common DNS checkers
# Visit online tools:
# - https://www.whatsmydns.net/
# - https://dnschecker.org/
# - https://mxtoolbox.com/
# Or use command line
for ns in 8.8.8.8 1.1.1.1 208.67.222.222; do
echo "Checking $ns:"
dig @$ns example.com +short
doneIf different DNS servers return different results, wait for DNS propagation to complete (can take 24-48 hours).
Check that DNS records are properly set up:
# Get authoritative nameservers for the domain
dig example.com NS
# Query the authoritative nameserver directly
dig @ns1.example.com example.com
# List all records for the domain
dig example.com ANYLog into your domain registrar (GoDaddy, Namecheap, Route 53, etc.) and verify:
- Nameservers are set correctly
- A/AAAA records exist for the domain
- CNAME records (if used) point to valid targets
- No conflicting or deleted records
The issue might be specific to the record type you're requesting:
const dns = require('dns').promises;
async function testAllRecordTypes(hostname) {
const types = ['A', 'AAAA', 'MX', 'TXT', 'NS', 'SOA'];
for (const type of types) {
try {
const records = await dns.resolveAny(hostname);
console.log(`✓ ${type}: Found records`);
} catch (err) {
console.log(`✗ ${type}: ${err.code}`);
}
}
}
testAllRecordTypes('example.com');If specific record types fail but others work, the domain configuration is incomplete for those types.
Test if the problem is specific to your configured DNS server:
const dns = require('dns');
async function resolveWithDifferentServers(hostname) {
const servers = [
'8.8.8.8', // Google
'1.1.1.1', // Cloudflare
'208.67.222.222' // OpenDNS
];
for (const server of servers) {
dns.setServers([server]);
try {
const addresses = await require('dns').promises.resolve4(hostname);
console.log(`✓ ${server}: ${addresses[0]}`);
return addresses[0];
} catch (err) {
console.log(`✗ ${server}: ${err.code}`);
}
}
}
resolveWithDifferentServers('example.com');If resolution works with public DNS but not your local/ISP DNS, the issue is with your DNS server's configuration.
If the domain uses CNAME records, verify the chain doesn't break:
# Trace CNAME chain
dig example.com
# If it shows CNAME, trace to the target
dig target.example.com
# Repeat until you reach an A record// Trace CNAME resolution
const dns = require('dns').promises;
async function traceCNAME(hostname) {
try {
const records = await dns.resolveCname(hostname);
console.log(`CNAME: ${hostname} -> ${records[0]}`);
return await traceCNAME(records[0]);
} catch (err) {
if (err.code === 'ENOTFOUND') {
console.log(`Final target not found: ${hostname}`);
} else {
const addresses = await dns.resolve4(hostname);
console.log(`A Record: ${hostname} -> ${addresses[0]}`);
}
}
}
traceCNAME('example.com');Handle NOTFOUND gracefully and provide fallback options:
const https = require('https');
function fetchWithFallback(primaryDomain, fallbackDomain) {
return new Promise((resolve, reject) => {
https.get(`https://${primaryDomain}`, (res) => {
resolve(res);
}).on('error', (err) => {
if (err.code === 'NOTFOUND') {
console.warn(`DNS NOTFOUND for ${primaryDomain}, trying fallback...`);
https.get(`https://${fallbackDomain}`, (res) => {
resolve(res);
}).on('error', reject);
} else {
reject(err);
}
});
});
}
fetchWithFallback('old-domain.com', 'new-domain.com')
.catch(err => console.error('All domains failed:', err.message));DNS Response Codes: The NOTFOUND error comes from DNS response code NXDOMAIN (Non-Existent Domain). Other DNS error codes include:
- NODATA (NOERROR + empty answer section)
- SERVFAIL (server failure)
- REFUSED (server refused query)
Node.js converts these to NOTFOUND when appropriate.
DNS Record Propagation: When you update DNS records, changes propagate through nameserver hierarchies. Even if your authoritative nameserver has the correct records, cached copies on other servers may be stale. TTL (Time To Live) values control how long caches hold records (typically 3600 seconds). Wait for TTL to expire before assuming propagation is complete.
Testing Specific Record Types: Different record types (A, AAAA, MX, etc.) can have different availability:
dig example.com A # IPv4 address
dig example.com AAAA # IPv6 address
dig example.com MX # Mail server
dig example.com TXT # Text records (SPF, DKIM, etc.)Only the record types you actually need must exist.
DNSSEC Validation: If DNSSEC is enabled, validation failures can appear as NOTFOUND. Test with DNSSEC disabled:
dig +cd example.com # Disable DNSSEC validationDocker/Container DNS Issues: Containers may have different DNS servers than the host. Check container's /etc/resolv.conf:
docker exec <container> cat /etc/resolv.confDifference from ENOTFOUND:
- NOTFOUND: Server responded with no records (domain doesn't exist)
- ENOTFOUND: Server didn't respond or couldn't be reached (timeout/unreachable)
NOTFOUND is faster to resolve (immediate response) while ENOTFOUND involves multiple retry attempts.
Custom DNS in Node.js: You can override default DNS servers at runtime:
const dns = require('dns');
dns.setServers(['8.8.8.8', '8.8.4.4']);Changes apply to all subsequent DNS operations in that process.
Error: EMFILE: too many open files, watch
EMFILE: fs.watch() limit exceeded
Error: Middleware next() called multiple times (next() invoked twice)
Express middleware next() called multiple times
Error: Worker failed to initialize (worker startup error)
Worker failed to initialize in Node.js
Error: EMFILE: too many open files, open 'file.txt'
EMFILE: too many open files
Error: cluster.fork() failed (cannot create child process)
cluster.fork() failed - Cannot create child process