diff --git a/code/currentTemp.js b/code/currentTemp.js new file mode 100644 index 0000000..1e8a12a --- /dev/null +++ b/code/currentTemp.js @@ -0,0 +1,24 @@ +const https = require('node:https'); + +const getCurrentTemp = function (response) { + let body = ""; + + response.on("data", (data) => { + body += data; + }); + + response.on("end", () => { + try { + let json = JSON.parse(body); + console.log(json.current_condition[0].temp_C + "°") + } catch (error) { + console.error(error.message); + }; + }); + +} + +const requestWeather = function () { + let url = "https://wttr.in/" + process.argv[2] + "?format=j1" + https.get(url, getCurrentTemp) +}