Discrepancy in Try Node.js Training module

Chris Wade-Evans 0 Reputation points
2024-12-21T12:37:25.5166667+00:00

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.

Azure Training
Azure Training
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.Training: Instruction to develop new skills.
2,036 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Rafael Canto 76 Reputation points
    2024-12-21T13:06:43.26+00:00

    Hi Chris,

    Actually the example uses the promise-based fetch instead of the original callback version. That's why the function is awaitable. I just tried it here with success.


  2. Pradeep M 5,680 Reputation points Microsoft Vendor
    2025-02-04T04:05:40.5333333+00:00

    Hi Chris Wade-Evans,

    Thank you for bringing this issue to our attention.

    Our team is aware of the problem and is actively working on a solution.

    In the meantime, we kindly ask that you proceed with the Learning Paths without completing the exercise modules. We will provide updates as soon as we have more information.

    Thank you for your patience and understanding.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.