Zach Templeton Zach Templeton - 11 months ago 59
Node.js Question

Node.js - Running a DELETE via HTTPS module

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: '',
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.on('error', (e) => {

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

[Error: getaddrinfo ENOTFOUND]
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: '',
host: '',
port: 443

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

Answer Source

The host key shouldn't contain the actual protocol of the URL you're using, i.e.,: host: '' should be host: ''

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