getWeather Example

node v10.24.1
version: 1.0.0
endpointsharetweet
const http = require("http") const getWeather = () => new Promise((resolve, reject) => { const options = { hostname: 'nodejs.org', path: '/dist/index.json', method: 'GET', }; http.get(options, (res) => { res.setEncoding('utf8'); let rawData = ''; res.on('data', (chunk) => { rawData += chunk; }); res.on('end', () => { try { const parsedData = JSON.parse(rawData); console.log(`Inside end listener. Logging out parsedData`, parsedData); resolve(parsedData); } catch (e) { reject(e); } }); }); }) const response = await getWeather() console.log(`response from getWeahter`, response)
Loading…

no comments

    sign in to comment