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

402
Views
Cómo usar node.js desde un archivo html para ir a otro archivo html y operar con variables de app.js, incluidos 2 archivos html

en index.html tengo un formulario que, después de escribir el nombre de la ciudad, envía información sobre el lugar y lo muestra:

 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 + ">");

y me gustaría que se muestre en weather.html

mi todo el código de 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!