- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Node.js - dns.resolveCname() Method
The dns.resolveCname() method uses the DNS protocol to resolve CNAME records for the hostname. The addresses argument passed to the callback function will contain an array of canonical records in an array.
Syntax
dns.resolveCname(hostname, callback)
Parameters
hostname – This parameter takes the input for the hostname to be resolved.
callback – This function will catch errors, if any.
addresses – Returns CNAME addresses for the hostname.
Example 1
Create a file with the name "resolveCname.js" and copy the following code snippet. After creating the file, use the command "node resolveCname.js" to run this code as shown in the example below −
// dns.resolveCname() Demo Example // Importing the dns module const dns = require('dns'); // Passing the argument below dns.resolveCname('tutorialspoint.com', (err, addresses) => console.log('addresses: %j', addresses));
Output
C:\home
ode>> node resolveCname.js QueryReqWrap { bindingName: 'queryCname', callback: [Function], hostname: 'tutorialspoint.com', oncomplete: [Function: onresolve], ttl: false, channel: ChannelWrap {} } addresses: undefined
Example 2
// dns.resolveCname() Demo Example // Importing the dns module const dns = require('dns'); // Passing the argument below dns.resolveCname('localhost', (err, addresses) => console.log('addresses: %j', addresses));
Output
C:\home
ode>> node resolveCname.js addresses: undefined
Advertisements