javascript-如何在 express.js 中设置使用 response.send () 发送的数据的样式
我想设置我在 app.post() 方法中发回的数据的样式。我怎样才能做到这一点?
这是 app.post() 代码:
app.post("/",function(req,res){
const query = req.body.cityName;
const cityName = query.charAt(0).toUpperCase() + query.slice(1);
const apiKey = "fc2f5f2ba2fe9d109d021ef0f57ef03d";
const unit ="metric";
const url = "https://api.openweathermap.org/data/2.5/weather?q=" + cityName + "&appid=" + apiKey + "&units=" + unit;
https.get(url,function(response){
console.log(response.statusCode);
response.on('data', function(data){
const weatherData = JSON.parse(data);
const temp = weatherData.main.temp;
const weatherDescription = weatherData.weather[0].description;
const icon = weatherData.weather[0].icon;
const imageURL = "http://openweathermap.org/img/wn/" + icon + "@2x.png";
res.write("<h1>The temperature in " + cityName + " is " + temp + " degrees Celcius</h1>");
res.write("<h3>The weather is currently " + weatherDescription + "</h3>");
res.write("<img src="+ imageURL +">");
res.send();
})
});
})