const express = require("express");
const https = require("https");
const app = express();
const url =
"https://api.openweathermap.org/data/2.5/weather?q=London,uk&units=metric&appid=0333cb6bfed722ca09f1062ec1ea9ca1";
app.get("/", (req, res) => {
https.get(url, response => {
response.on("data", data => {
const weatherData = JSON.parse(data);
const temp = weatherData.main.temp;
const { description, icon } = weatherData.weather[0];
const imageURL = `http://openweathermap.org/img/wn/${icon}@2x.png`;
res.set("Content-Type", "text/html");
res.setHeader("Content-Type", "text/html");
res.send(`
<h3>The weather is currently ${description}</h3>
<img src="${imageURL}">
<h1>The temperature in London is <span>${temp}</span> ° Celsius.</h1>
`);
});
});
});
app.listen(3000, () => {
console.log("Server started!!!");
});