Skip to content
Related Articles

Related Articles

Node.js https.request() Function

View Discussion
Improve Article
Save Article
  • Last Updated : 08 Oct, 2021

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
Recommended Articles
Page :

Start Your Coding Journey Now!