Looking up DNS records programmatically can be very useful for testing and debugging domain configurations. In this comprehensive guide, we will explore how to use the Geekflare DNS Lookup API to retrieve DNS records in Node.js.
Overview of the Geekflare DNS Lookup API
The Geekflare DNS Lookup API allows you to lookup DNS records for a domain programmatically. It supports retrieving common record types like A, AAAA, CNAME, MX, NS, SOA, TXT.
Some key features of the API include:
- Simple REST API with JSON response
- No rate limits or quotas
- Global API endpoints for fast worldwide DNS lookups
- HTTPS endpoint for secure connections
- CORS enabled for use from web apps
The API is very easy to use. All you need to do is make a POST request with the domain name and record type, and it will return the DNS records in a JSON response.
Prerequisites
To follow along with this guide, you will need:
- Node.js installed on your system
- A Geekflare account and API key
Get a Geekflare API Key
To use the Geekflare API, you will need an API key which can be obtained from your Geekflare account dashboard.
Sign up for a free Geekflare account if you don‘t have one already. Once you‘re logged into your dashboard, you can get your API key from the Integrations > API Access page.

Make sure to keep this API key secure, as it provides full access to your Geekflare account.
Making DNS Lookups with Node.js Core Modules
We will first look at how to use the DNS Lookup API with Node.js core modules like http and https. While this is a bit more verbose than using a client library, it demonstrates how to make API requests at a low level.
Create a new Node.js file dns-lookup.js and let‘s get started!
1. Require the necessary modules
We need to require the Node.js https and querystring modules:
const https = require(‘https‘);
const querystring = require(‘querystring‘);
https allows us to make HTTPS requests to the API endpoint.
querystring helps format the request body data as a query string.
2. Set request options
Next we‘ll define an object with the request options:
const options = {
hostname: ‘api.mcngmarketing.com‘,
path: ‘/dnsrecord‘,
method: ‘POST‘,
headers: {
‘Content-Type‘: ‘application/x-www-form-urlencoded‘,
‘Content-Length‘: data.length,
‘x-api-key‘: API_KEY // replace with your actual API key
}
};
This includes the API hostname, path, HTTP method, headers, and authentication details.
3. Define request body data
The API expects the domain name and record type in the request body, so we need to format that:
const data = querystring.stringify({
url: ‘example.com‘,
types: [‘A‘]
});
Here we are looking up the A records for example.com.
4. Make the API request
Now we can make the HTTPS request to the API endpoint:
const req = https.request(options, res => {
// Handle response here
});
req.write(data);
req.end();
This will initiate the request and write the body data to it.
5. Process the response
Inside the callback, we can handle the response when it arrives:
let body = ‘‘;
res.on(‘data‘, chunk => {
body += chunk;
});
res.on(‘end‘, () => {
const records = JSON.parse(body);
console.log(records);
});
We append chunks of response data to the body variable. Once the full response has been received, we parse it as JSON and log the DNS records.
And that‘s it! We‘ve now made a DNS lookup using core Node.js modules.
While it involved more code, this shows how to make API requests directly without any external dependencies.
Making DNS Lookups with Fetch API
Next, we‘ll look at a simpler way to use the DNS Lookup API with the Fetch API. The Fetch API provides a modern way to make network requests that is supported in Node.js.
Create another file dns-fetch.js.
1. Import the Fetch API
At the top of the file, import the node-fetch module which implements fetch() for Node.js:
const fetch = require(‘node-fetch‘);
2. Make the API request
We can now directly call fetch() and await the response:
const response = await fetch(‘https://api.mcngmarketing.com/dnsrecord‘, {
method: ‘POST‘,
headers: {
‘Content-Type‘: ‘application/json‘,
‘x-api-key‘: API_KEY // Replace with your actual API key
},
body: JSON.stringify({
url: ‘example.com‘,
types: [‘A‘]
})
});
The fetch() method makes the API request. We pass the endpoint URL, headers with the API key, and the request body with the domain name and record type.
3. Process the response
To get the response data, we need to parse it from JSON:
const records = await response.json();
console.log(records);
And that gives us the DNS records!
The Fetch API provides a very concise way to make requests and handle responses compared to the verbose core modules.
Making DNS Lookups with Axios
Lastly, we‘ll look at using the popular Axios library to call the DNS Lookup API.
Axios is Promise based like fetch() and makes working with APIs very straightforward.
Create a file dns-axios.js and let‘s get started.
1. Import Axios
First import Axios at the top:
const axios = require(‘axios‘);
2. Make the API request
To make the request, call axios.post() and await the response:
const response = await axios.post(‘https://api.mcngmarketing.com/dnsrecord‘, {
url: ‘example.com‘,
types: [‘A‘]
}, {
headers: {
‘Content-Type‘: ‘application/json‘,
‘x-api-key‘: API_KEY // Replace with your actual API key
}
});
Axios accepts the URL, request body, and headers much like Fetch.
3. Process the response
The response data is available on the data property:
const records = response.data;
console.log(records);
And we have our DNS records! Axios provides a very clean API for calling REST endpoints.
Conclusion
In this guide, we covered multiple ways to use the Geekflare DNS Lookup API with Node.js:
- With core Node.js modules like
http,https, andquerystring - Using the Fetch API for simple promise-based requests
- With the Axios library for an easy API client
The DNS Lookup API enables you to lookup DNS records on demand for testing and automation. There are also many other APIs available like screenshotting, load testing, SSL testing, and more.
I hope this helps you get started with programmatically looking up DNS records using Node.js! Let me know if you have any other questions.