In the Try Node.js training module. In the section Add a top-level asynchronous function there is a discrepancy between the code you are asked to add and the explanation of the code. It seems that the explanation refers to an older method.
Add the following code to the index.js file to create an asynchronous HTTP request:
‘’’JavaScript
Copy
import fetch from 'node-fetch';
console.log(start);
try {
const res = await fetch('https://github.com/MicrosoftDocs/node-essentials');
console.log('statusCode:', res.status);
} catch (error) {
console.log(error: ${error});
}
console.log(end);’’’
The https.get method makes an HTTP request to the Node.js website and returns the response. The get method takes two parameters: the URL to request and a callback function that is called when the response is received. The callback function takes a single parameter, res, which is the response object.