Answers for "http request without a library in javascript"

1

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();
Posted by: Guest on September-11-2020

Code answers related to "http request without a library in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language