0

I am trying to build a Node.js console app that will call back to an Azure REST endpoint. Specifically, I would like to use the DELETE action on an endpoint. I can successfully setup the request in Fiddler. Yet, I can't seem to get the call to work from Node. I'm using the HTTPS module, where I'm trying the following:

console.log('deleting search index.');
var options = {
  host: 'https://test-service.search.windows.net',
  path: '/indexes/test?api-version=2015-02-28',
  port: 443,
  method: 'DELETE',
  headers: {
    'api-key': '[Hidden]'
  }
};

var req = https.request(options, (res) => {
  console.log('statusCode:', res.statusCode);
  console.log('headers:', res.headers);

  res.on('data', (d) => {});
});
req.end();

req.on('error', (e) => {
  console.error(e);
});

When I run this, I get an error that says:

{ 
  [Error: getaddrinfo ENOTFOUND https://test-service.search.windows.net https://test-service.search.windows.net:443]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'https://test-service.search.windows.net',
  host: 'https://test-service.search.windows.net',
  port: 443 
}

What am I doing wrong? This looks correct to me.

Some User
  • 5,257
  • 13
  • 51
  • 93

1 Answers1

1

The host key shouldn't contain the actual protocol of the URL you're using, i.e.,: host: 'https://test-service.search.windows.net' should be host: 'test-service.search.windows.net'

If you're already using the https module it already knows the protocol.

Resources:

Community
  • 1
  • 1
Dennis Tang
  • 216
  • 1
  • 5