Create a TypeScript function that accepts a URL and returns the title of the web page at that URL by making an HTTP request and parsing the HTML response.
PLAINFORMAT
import fetch from 'node-fetch';
import * as cheerio from 'cheerio';

// Function to get the title of a web page from its URL
async function getTitleFromUrl(url: string): Promise<string | null> {
  try {
    const response = await fetch(url);
    if (!response.ok) {
      throw new Error(`Error fetching URL: ${url}`);
    }

    const html = await response.text();
    const $ = cheerio.load(html);
    const title = $('head > title').text();

    return title;
  } catch (error) {
    console.error(error);
    return null;
  }
}

// Example usage:
(async () => {
  const url = 'https://www.example.com/';
  const title = await getTitleFromUrl(url);
  console.log(`Title of ${url}:`, title);
})();