solved Task 2
This commit is contained in:
parent
a8257389ad
commit
514197ee34
|
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue