nodejs request api

// Step 1: Import the 'request' module
const request = require('request');

// Step 2: Set the API endpoint URL
const apiUrl = 'https://api.example.com/data';

// Step 3: Define the request options
const options = {
  url: apiUrl,
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
  }
};

// Step 4: Make the API request using the 'request' module
request(options, (error, response, body) => {
  // Step 5: Check for errors
  if (error) {
    console.error('Error:', error);
    return;
  }

  // Step 6: Check the HTTP status code
  if (response.statusCode !== 200) {
    console.error('Unexpected status code:', response.statusCode);
    return;
  }

  // Step 7: Parse the JSON response
  const data = JSON.parse(body);

  // Step 8: Process the API response data
  console.log('API Response:', data);
});