in index.html I have a form which, after typing the city name, sends information about the place and displays it:
res.write("<p>The weather is currently " + desc + "</p>");
res.write("<h1>The temperature in " + query + " is " + temp + " degrees Celcuis.</h1>");
res.write("<img src=" + imageURL + ">");
and I would like it to be displayed in weather.html
my all code from app.js:
const express = require("express");
const https = require("https");
const bodyParser = require("body-parser");
const app = express();
const path = require('path'); //to CSS work
app.use(bodyParser.urlencoded({ extended: true })); //using body parser
app.use(express.static(path.join(__dirname, 'public'))); //to CSS work
app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
});
app.post("/", (req, res) => {
const query = req.body.City;
const keyAPI = "mykey";
const units = "metric";
const url = "https://api.openweathermap.org/data/2.5/weather?q=" + query + "&appid=" + keyAPI + "&units=" + units + "";
https.get(url, (response) => {
console.log(response.statusCode);
response.on("data", (data) => {
const weatherData = JSON.parse(data);
const temp = weatherData.main.temp;
const desc = weatherData.weather[0].description;
const imageIcon = weatherData.weather[0].icon;
const imageURL = "http://openweathermap.org/img/wn/" + imageIcon + "@2x.png";
//res.sendFile(__dirname + "/weather.html"); <-- It doesn't work'
res.write("<p>The weather is currently " + desc + "</p>");
res.write("<h1>The temperature in " + query + " is " + temp + " degrees Celcuis.</h1>");
res.write("<img src=" + imageURL + ">");
res.send();
});
});
});
app.listen(3000, () => {
console.log("Server is running on port 3000.");
});