Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Node.js – Uncaught TypeError: Cannot read properties of undefined (reading 'get')

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’)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading