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

266
Visualizações
Node : Put request is not updating the request data on the browser but updates on Command Line, Weather API

I'm a beginner in Node, as I try to update the API request(Weather API) in the browser it never changes but if I try to run on command line it forecast the live weather.

const express = require("express");
const { all } = require("express/lib/application");
// HTTPS library requrired`
const https = require("https");
const app = express();
const port = 3000;
app.get("/", function(req, res){

    // Getting data from external server
    const url = "https://api.openweathermap.org/data/2.5/weather?q=Mumbai&appid=---------------------------------&units=metric";

    // Adding functions to our own server
    https.get(url, function(respone){
        console.log(respone.statusCode);

        // Getting data and putting on our server
        respone.on("data", function(data){

            // Parsing the data to an actuall javascript object
            var allData = JSON.parse(data)
            const temp = allData.main.temp;
            const description = allData.weather[0].description;
            const icon = allData.weather[0].icon;
            const imageUrl = "http://openweathermap.org/img/wn/"+ icon +"@2x.png"
            res.write("<p>The weather type here is: "+description+"</p>")
            res.write("<h1>The temperature here is: "+temp+"</h1>")
            res.write("<img src = "+imageUrl+"></img>");
            res.send();
            console.log(allData)
        })
    })
})

app.listen(port, function(){
    console.log("Server is running on port 3000");
})

Command Line image Browser Image

about 4 years ago · Juan Pablo Isaza
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