Last active
August 11, 2019 05:25
-
-
Save rintoandrews90/13fcb265d3eed8b5cbadaa2ebbc1bf91 to your computer and use it in GitHub Desktop.
Make http request in node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Install HTTP Request | |
// npm init -y | |
// npm i request | |
const request = require('request') | |
const url = "https://api.darksky.net/forecast/fb190dafa7914f0bb56e65287631fad9/37.8267,-122.4233" | |
request({url:url}, (error,response) => { | |
const data = JSON.parse(response.body) | |
//console.log(data) | |
console.log(data.currently) | |
}) | |
// JSON response | |
const request = require('request') | |
const url = "https://api.darksky.net/forecast/fb190dafa7914f0bb56e65287631fad9/37.8267,-122.4233" | |
request({url:url,json:true}, (error,response) => { | |
console.log('It is currently '+response.body.currently.temperature + ' degress. There is a ' + response.body.currently.precipProbability + ' chance of rain') | |
}) | |
//Convert address to latitude/longitude | |
const gioCodeURL = "https://api.mapbox.com/geocoding/v5/mapbox.places/Los%20Angeles.json?access_token=pk.eyJ1IjoicmludG8iLCJhIjoiY2p6NmllczBiMG1nbjNucG5qZjVqOXZwZSJ9.qu2LrgatHMB-so2E4oHaFA&limit=1" | |
request({url:gioCodeURL,json:true}, (error,response) => { | |
const latitude = response.body.features[0].center[0] | |
const longitude = response.body.features[0].center[1] | |
console.log('Latitude'+ latitude + ' Longitude ' + longitude) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment