I have written this code for weather app how to change the background and CSS properties of the page the data is getting posted
app.post("/", (req, res) => {
const query = req.body.cityName;
const apiKey = "48a9ebfd3c72f0c53af5c483631e82ad";
const unit = "metric";
const url = "https://api.openweathermap.org/data/2.5/weather?q=" + query + "&appid=" + apiKey + "&units=" + unit;
https.get(url, (response) => {
console.log(response.statusCode);
response.on("data", (d) => {
const weatherData = JSON.parse(d);
const weatherDescription = weatherData.weather[0].description;
const temp = weatherData.main.temp;
const windSpeed = weatherData.wind.speed;
const pressure = weatherData.main.pressure;
const icon = weatherData.weather[0].icon;
const imageUrl = "http://openweathermap.org/img/wn/" + icon + "@2x.png";
res.write("<p>Temperature " + query + " is " + temp + " degrees celcius.</p>");
res.write("<p> Weather description - " + weatherDescription + "</p>");
res.write("<p>Wind speed " + windSpeed + " Km/hr </h4>");
res.write("<p>Pressure is " + pressure + " mbar </p>");
res.write("<img src=" + imageUrl + "> ");
res.send();
});
});
});
I understand from your comments now :)
If you want to change the css, you need to add a style property to your html tags.
For example:
res.write("<p style='background-color:red;'>Temperature " + query + " is " + temp + " degrees celcius.</p>");
You can find more information here: https://www.w3schools.com/html/html_css.asp#:~:text=try%20it%20yourself.-,Inline%20CSS,-An%20inline%20CSS