开发者

Using Node.js, how can I check whether a domain name is registered?

开发者 https://www.devze.com 2023-02-10 23:17 出处:网络
I\'m building a simple webapp to teach myself node.js, and in it I need to check whether a certain domain name specified by the user is registered. I\'m not really sure how to go about this and I\'d a

I'm building a simple webapp to teach myself node.js, and in it I need to check whether a certain domain name specified by the user is registered. I'm not really sure how to go about this and I'd appreciate it if anybody coul开发者_如何学God enlighten me.


Take a look at this article by Matt Brubeck:

http://limpet.net/mbrubeck/2010/01/13/si-unit-domains-node-js.html

There is a Node.js script that does exactly that.


I think the best way to do this is to use the dns module to do a resolve, and if nothing is returned or an error is thrown it's not registered yet.

https://nodejs.org/api/dns.html


I did not found the correct answer for this question. My solution is over here

https://www.npmjs.com/package/whois


Run something like this:

//loads the Node core DNS module
var dns = require ( 'dns' )

function checkAvailable( url ) {
  //uses the core modules to run an IPv4 resolver that returns 'err' on error
  dns.resolve4( url, function (err, addresses) {
    if (err) console.log (url + " is possibly available : " + err)
  })
}
// calls the function of a given url        
checkAvailable( "ohwellhaithar.com" )
0

精彩评论

暂无评论...
验证码 换一张
取 消