Beginning require use with an NPM package

suggest change

Modern Node.js includes the web-standard fetch() API (global fetch since Node.js 18), so a simple HTTP request does not require an npm package:

async function getWeather(url) {
    const response = await fetch(url);
    if (!response.ok) {
        throw new Error(`HTTP ${response.status}: ${response.statusText}`);
    }
    return response.json();
}

getWeather('https://example.com/weather')
    .then(console.log)
    .catch(console.error);

fetch() resolves to a Response; check response.ok before decoding the response body.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents