Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

219
Visualizações
How to send data received from api to my designed html page

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");
 });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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:

  1. When a user opens the site
  2. The controller would call the API and get a response
  3. Render the .ejs page with the response

Here is the Getting Started page of EJS: https://ejs.co/#install

Another recommendation:

  • Use relative paths for all the files. The advantage here is, nothing breaks if one moves the project.
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda