Jonathan Allen Grant Jonathan Allen Grant - 2 months ago 43
Node.js Question

When I try to do a https post request in node, I get a getaddrinfo ENOTFOUND error

The full error is this:

events.js:160
throw er; // Unhandled 'error' event
^

Error: getaddrinfo ENOTFOUND https://api.instagram.com https://api.instagram.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:79:26)


and my code to get just the error is this:

var express = require('express');
var app = express();
var https = require('https');

app.get('/oauth/ig', function (req, res) {
var options = {
hostname: 'https://api.instagram.com',
path: '/oauth/access_token?client_secret=myClientSecret&grant_type=authorization_code&redirect_uri=http://localhost:1992/oauth/ig&code='+req.query.code,
method: 'POST',
};
var igRequest = https.request(options, (response) => {
res.send("fuck it");
});
})


I am using nodejs and am trying to do the Instagram OAUTH.

Answer

hostname should be just the host name, not including the protocol:

hostname: 'api.instagram.com',