I am attempting to do an external GET request out to an endpoint requesting a general response of information. I have checked out a number of ways this can be done through node and have built the below request(some information such as hostname have been changed).
The problem I seem to run into that while my options are being declared and I am able to console.log them before the https.get command, once the https.get command is run I get the following error
Uncaught TypeError: Cannot read properties of undefined (reading ‘get’)
Here is the code of the request
var https = require("https");
function getInformation()
{
var header = generateHeader();
console.log("header " + header);
const options =
{
hostname: 'testUrlhere',
path: '/api/v1/partners',
port: '443',
headers: {'Authorization': header }
}
https.get(options,function(res){
res.setEncoding('utf8');
res.on('data', function(chunk){
console.log('response:' + chunk)
});
});
}
From the code I am not identifying what might be causing the problem so any assistance would be appreciated as I am not used to Node.js
>Solution :
You have probably not imported the https module prior to usage, try adding an import statement in the top of your file like this:
import https from 'https'
If you are using commonJS then try the following instead:
const https = require('node:https')