【发布时间】:2023-03-30 14:50:02
【问题描述】:
我在这里写了一个代码,我想知道“response.on”在做什么以及我们为什么要传递“数据”,这个“数据”是什么。 “.on”到底是做什么用的。
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=London&appid=5c8618a9210a11846accc217f3b3084f";
https.get(url,function(respons){
response.on("data",function(data){
const wht = JSON.parse(data)
temp = wht.main.temp
res.send("temp "+ temp)
})
})
})
app.listen(3000, function(){
console.log("running");
});
【问题讨论】:
标签: javascript node.js express node-modules