【问题标题】:Css not loading on node.js expressCss没有加载到node.js express上
【发布时间】:2021-07-12 19:15:06
【问题描述】:

我正在使用 node.js,表达到天气应用程序,但 css 没有加载,我确实按照这个链接 Text,但到目前为止还没有成功,而且我的公用文件夹中有 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();
        })
    });
})

【问题讨论】:

  • 包含这个&lt;link&gt;的HTML页面是如何加载的?也通过快递服务器?控制台/网络中是否有错误?
  • ,控制台没有错误

标签: javascript css node.js express


【解决方案1】:

尝试清除缓存并重新加载。点击ctrl + shift + i,右键浏览器刷新按钮,选择第三个选项。

【讨论】:

  • 不幸的是还是一样,我会尝试复制项目,看看以后会发生什么
猜你喜欢
  • 2022-01-06
  • 1970-01-01
  • 2017-08-22
  • 2021-11-09
  • 2021-04-26
  • 1970-01-01
  • 2018-03-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多