Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!