showing results for - "http request without a library in javascript"
Julia
18 Mar 2016
1const http = require('http');
2const url = 'http://api.weatherstack.com/current?access_key=29f9cf0e577a785e1dfb23a049e2336c&query=40,-75';
3
4const request = http.request(url, (response) => {
5    let data = ''
6    response.on('data', (chunk)=> { // data is event name here
7        data = data + chunk.toString();
8    })
9
10    response.on('end', () => {
11       const body = JSON.parse(data);
12       console.log(body);
13    })
14})
15
16request.on('error', (error) => {
17    console.log('An erorr', error);
18})
19
20request.end();