Dhruv
Dhruv

Reputation: 173

Node JS - HTTP module error

Error: getaddrinfo ENOTFOUND jsonplaceholder.typicode.com/ jsonplaceholder.typicode.com/:80
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

My code look like this -

  var test = await new Promise((resolve, reject) => {
    var options = {
      host: 'jsonplaceholder.typicode.com/',
      path: '/posts/1'
    };

    var req = http.request(options);
    req.end();

    req.on('connect', (res, socket, head) => {
      socket.on('data', (chunk) => {
        resolve(chunk.toString());
      });

      socket.on('end', () => {
        proxy.close();
      });
    });
});

It seems there is a issue with port number but i can not figure out, Please help me to identify the issue.

Upvotes: 0

Views: 399

Answers (1)

Matt Altepeter
Matt Altepeter

Reputation: 956

Remove the trailing slash from the host property of your options

Upvotes: 1

Related Questions