[英]Css not loading on node.js express
我正在使用 node.js,快遞到天氣應用程序,但是 css 沒有加載,我確實按照這個鏈接文本,但到目前為止沒有成功,我確實在公共文件夾中有 css
html
<link rel="stylesheet" href="/css/style.css">
js
//local server up and running
const express = require("express");
//node internal request
const https = require("https");
const app = express();
//css
app.use(express.static(__dirname + "public"));
app.get("/", function (req, res) {
const query = "Liverpool";
const apiKey = "3af2a1822cfe6d31e4317ac9c4b5d531";
const unit = "metric";
const url = "https://api.openweathermap.org/data/2.5/weather?q=" + query +"&appid="+ apiKey + "&units=" + unit;
https.get(url, function(response){
console.log(response.statusCode);
response.on("data", function(data){
//convert hexadecimal to js
const weatherData = JSON.parse(data);
//asking the items that we want
const temp = weatherData.main.temp;
const weatherDescription = weatherData.weather[0].description;
const cityName = weatherData.name;
const icon = weatherData.weather[0].icon;
const imgURL = "https://openweathermap.org/img/wn/" + icon + "@2x.png";
res.write("<p>The weather is currently " +weatherDescription + "</p>");
res.write("<h1>The temperature in " + cityName + " is " + Math.round(temp) + " degree Celsius</h1>");
res.write("<img src=" + imgURL + ">");
res.send();
})
});
})
嘗試清除緩存並重新加載。 單擊 ctrl + shift + i,右鍵單擊瀏覽器刷新按鈕和 select 第三個選項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.