Dns.lookup always callbacks err

I’m doing
Url shortener project and i dns.lookup like this

// your first API endpoint... 
app.post("/api/shorturl/new", (req, res) => {
  let url = req.body.url;
  console.log(url);
  dns.lookup(url,(err) => {
    console.log(err);
res.send('ok');
  })
});

and if i send https://www.freecodecamp.org
console.log(err) prints that

{ Error: getaddrinfo ENOTFOUND https://www.freecodecamp.org

    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)

  errno: 'ENOTFOUND',

  code: 'ENOTFOUND',

  syscall: 'getaddrinfo',

  hostname: 'https://www.freecodecamp.org' }

Just found it
i removed the protocol
i have to pass
www.google.com
not
https://www.google.com
to dns.lookup()

1 Like