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

406
Views
How to use node.js from one html file to go to another html file and operate on variables from app.js including 2 html files

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.");
});
about 4 years ago · Juan Pablo Isaza
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!