How to use the get function from https

Find comprehensive JavaScript https.get code examples handpicked from public code repositorys.

16
17
18
19
20
21
22
23
24
25
 */
const getHttpsSite = (url, timeout) => {
    if(timeout === undefined) timeout = 10000;
    let timeoutId;
    return new Promise((resolve) => {
        const req = https.get(url, function(res) {
            console.log(`Got response: ${ res.statusCode }`, "From", url);
            let content = '';
            res.on('data', function(chunk) {
                content += chunk;
fork icon0
star icon1
watch icon1

+ 3 other calls in file

67
68
69
70
71
72
73
74
75
76
77
78
79
})


app.get('/convert/:secureUrl', (req, res)=>{


    // Fetch from the secure URl
    https.get('https://res.cloudinary.com/dianptniw/raw/upload/v1677197823/1677197821712-file-1677197821712-154357189.xlsx',
        function(chunkRes) {
        const chunks = [];


        chunkRes.on('data', function(chunk) {
fork icon0
star icon0
watch icon1

448
449
450
451
452
453
454
455
456
457
458
}


async function download(url, filename) {
  const filePath = path.join(os.tmpdir(), filename ?? path.basename(url));
  const file = fs.createWriteStream(filePath);
  const request = https.get(url, (response) => response.pipe(file));
  await new Promise((resolve, reject) => {
    file.on("finish", resolve);
    [file, request].forEach((stream) => stream.on("error", reject));
  });
fork icon0
star icon0
watch icon1

54
55
56
57
58
59
60
61
62
63
64


function getUserName(req, res, next) {
    var access_token = req.session.token.access_token;
    var profile_url = 'https://ion.tjhsst.edu/api/profile?format=json&access_token=' + access_token;
    
    https.get(profile_url, function(response) {
        var rawData = '';
        response.on('data', function(chunk) {
            rawData += chunk;
        })
fork icon0
star icon0
watch icon1

26
27
28
29
30
31
32
33
34
35
36
  makeRequest();
  assert(agent.sockets.hasOwnProperty(name)); // Agent has indeed been used
}));


function makeRequest() {
  const req = https.get({
    port: server.address().port
  });
  req.on('close', () =>
    server.close());
fork icon0
star icon0
watch icon0

62
63
64
65
66
67
68
69
70
71
      server.close();
    } else {
      // Save `value` for check the next time.
      const [key, val] = next.value;
      value = val;
      https.get({ ...getBaseOptions(port), [key]: val },
                variations(iter, port, cb));
    }
  }));
});
fork icon0
star icon0
watch icon0

+ 3 other calls in file

22
23
24
25
26
27
28
29
30
31
  rejectUnauthorized: false,
}, (res) => {
  res.resume();
  res.on('end', () => {
    // Trigger TLS connection reuse
    https.get({
      port: server.address().port,
      rejectUnauthorized: false,
    }, (res) => {
      server.close();
fork icon0
star icon0
watch icon0

+ 3 other calls in file