我尝试使用https.get()打印响应,但似乎无法正常工作

时间:2020-03-28 06:52:59

标签: api https request

我正在尝试获取一个api并在控制台上打印响应。我使用nodemon运行服务器,但是打开本地网站时控制台上没有任何内容。

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

const app =express();

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

    const url ="https://api.openweathermap.org/data/2.5/weather?q=Kolkata&appid=deb2be0d81bc172121c595d50dcc7b48&units=metric";

    https.get(url, (response) => {

        console.log(response);
    }); 

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

});


app.listen(3000,function(){

    console.log("Server is running on port 3000");
});

终端只是向我展示了这一点

Terminal pic

0 个答案:

没有答案