https api request is not working with https.get(url)

I need to pull the weather API data from

https://api.weatherapi.com/v1/current.json?key=f5f45b956fc64a2482370828211902&q=London

It gives a response when pasted in the web browser as well as in postman. But, once incorporated in javascript https.get it fails by continuously loading the browsers and hanging the terminal with unwanted informations.

app.js :

//jshint esversion:6

const express = require("express");
const https = require("https");

const app = express();


app.get("/",function(req, res){

  const url = "https://api.weatherapi.com/v1/current.json?key=f5f45b956fc64a2482370828211902&q=London";

  https.get(url,function(response){
    //console.log(response);

    response.on("data",function(data){
      const weatherData = JSON.parse(data);
      const temp = weatherData.current.temp_c;
      const weatherDescription = weatherData.current.condition.text;
    });
  });

  res.send("Server is up and running");

});


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

129 thoughts on “https api request is not working with https.get(url)”

  1. Hello there! This blog post could not be written any better!
    Going through this article reminds me of my previous roommate!
    He constantly kept preaching about this. I’ll send this post
    to him. Pretty sure he’ll have a good read.
    Thank you for sharing!

    Reply
  2. Fantastic website you have here but I was curious if you knew of any
    discussion boards that cover the same topics talked about in this article?

    I’d really love to be a part of online community where I can get suggestions from other experienced individuals that share the same interest.
    If you have any recommendations, please let me know.
    Thank you!

    Reply
  3. It is appropriate time to make some plans for the future and it is
    time to be happy. I’ve read this post and if I could I desire to suggest you few interesting
    things or tips. Maybe you can write next articles referring
    to this article. I wish to read more things about it!

    Reply
  4. Great goods from you, man. I’ve understand your stuff previous to and
    you are just extremely excellent. I actually like what you’ve acquired here, certainly like what you are saying and the way in which you say it.
    You make it entertaining and you still care for to keep it sensible.

    I cant wait to read much more from you. This is actually
    a tremendous web site.

    Reply
  5. Wow that was strange. I just wrote an incredibly long comment but after I clicked submit my comment
    didn’t appear. Grrrr… well I’m not writing all that
    over again. Anyhow, just wanted to say great blog!

    Reply
  6. Right here is the right site for everyone who would like to find out about this topic.
    You know a whole lot its almost hard to argue with
    you (not that I personally would want to…HaHa). You certainly put a brand new spin on a topic that’s been discussed for a long
    time. Excellent stuff, just wonderful!

    Reply
  7. You really make it seem so easy with your presentation however I in finding
    this matter to be really one thing which I think I’d by no
    means understand. It sort of feels too complex and extremely vast for me.
    I am looking forward on your next put up, I’ll attempt
    to get the hold of it!

    Reply