execute http request without library js code example

Example: http request without a library in javascript

const http = require('http');
const url = 'http://api.weatherstack.com/current?access_key=29f9cf0e577a785e1dfb23a049e2336c&query=40,-75';

const request = http.request(url, (response) => {
    let data = ''
    response.on('data', (chunk)=> { // data is event name here
        data = data + chunk.toString();
    })

    response.on('end', () => {
       const body = JSON.parse(data);
       console.log(body);
    })
})

request.on('error', (error) => {
    console.log('An erorr', error);
})

request.end();