Node.js dns resolve() via web service

Description

Node.js dns resolve() via web service


var dns=require('dns'),
  http=require('http');

var s=http.createServer(function(req, res){
  res.writeHead(200, {'Content-Type':'text/plain'});

  var query=req.url.replace('/', '');
  dns.resolve(query,function(err, addresses){
    if (!err) {/*from   w w  w.ja v a 2s  .c  o m*/
      res.end(JSON.stringify(addresses)+'\n');
    }else{
      res.end(err.message);
    }
  });
});
s.listen(8000);



PreviousNext

Related