Sush
Sush

Reputation: 1457

Node.js: HTTP get request

I am trying to write a node.js script as follows

var https = require('https');
var options = {
  hostname: 'https://172.16.2.51',
  port: 9090,
  path: '/vm/list',
  method: 'GET',                
};

var req = https.request(options, function(res) {
  res.on('data', function(d) {
    process.stdout.write(d);
  });
});

req.end();
req.on('error', function(e) {
  console.error(e);
});

When I run the script, I get this error:

{ [Error: getaddrinfo ENOENT] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }

Upvotes: 0

Views: 388

Answers (1)

hexacyanide
hexacyanide

Reputation: 91799

The hostname property of options should be an IP address or a domain name. In your example, get rid of the protocol. So change this:

var options = {
  hostname: 'https://172.16.2.51',
  port: 9090,
  path: '/vm/list',
  method: 'GET'
};

To this:

var options = {
  hostname: '172.16.2.51',
  port: 9090,
  path: '/vm/list',
  method: 'GET'
};

Upvotes: 3

Related Questions