basically i am a beginner in web-development i have designed a basic weather report website using Openweather api i have received data from api but the main problem is i am not able to pass the data from api to my html page and i have even used DOM to send the information but it did not work.
'''
const express = require("express");
const bodyParser = require("body-parser");
const http = require("http");
var app = express();
app.use(bodyParser.urlencoded({extended:true}));
app.use(express.static("./public"));
app.get("/",(request,response)=>{
response.sendFile('/Users/vivek/Desktop/web-development/weather-
app/public');
});
app.get("/weatherdata",(request,response)=>{
response.sendfile('/Users/vivek/Desktop/web-development/weather-
app/public/weatherData.html');
})
app.post("/weatherdata",(req,res)=>{
res.sendfile('./public/weatherData.html');
var cityname = req.body.cityName;
var apiid = "b75642448cbd207923a63b89cf48768d";
var url = "http://api.openweathermap.org/data/2.5/weather?
q="+cityname+"&appid="+apiid;
http.get(url,(res=>{
console.log(res.statusCode)
res.on("data",(data)=>{
data = JSON.parse(data);
temp = data.main.temp;
console.log(temp);
document.querySelector(".main-degree").innerHTML=temp;
})
}))
})
app.listen(7000,()=>{
console.log("sever is running on port 7000");
});
Expanding on the comment, you can use a templating engine like ejs. As the name suggests, it is a template that you render with the response from the Openweather API.
Basic Process:
Here is the Getting Started page of EJS: https://ejs.co/#install
Another recommendation: