Node.js | https.request() Function

Node.js provides two core modules for making http requests. The http module can be used to make http requests and the https module can be used to make https requests. One great feature of the request is that it provides a single module that can make both http and https requests.

Feature of https module:

  1. It is easy to get started and easy to use.
  2. It is widely used and popular module for making https calls.

Create a folder and add a file for example index.js, To run this file you need to run the following command.

node index.js

Filename: index.js





const https = require('https');
// Sample URL
const request = https.request(url, (response) => {
    let data = '';
    response.on('data', (chunk) => {
        data = data + chunk.toString();
    response.on('end', () => {
        const body = JSON.parse(data);
request.on('error', (error) => {
    console.log('An error', error);


Steps to run the program:

  • Run index.js file using below command:
    node index.js

    Output of above command

So this is how you can use the https.request() function to make https request calls.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.