Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda