To fix Node js Error: Protocol "https:" not supported. Expected "http:", we use https.get method.
For instance, we write
const http = require("http");
const https = require("https");
const url = new URL("https://www.example.com");
const client = url.protocol == "https:" ? https : client;
const req = client.get(url, (res) => {
console.log(res);
});
to get the client according to the url‘s protocol.
We use the https client if it’s https and http if it’s http.
Then we call get with the client for the right protocol to make the get request.