简体   繁体   English

Css 未加载 node.js 快递

[英]Css not loading on node.js express

I'm using node.js, express to a weather app, but the css is not loading, I did followed this link Text , but not success so far and I do have the css inside a public folder.我正在使用 node.js,快递到天气应用程序,但是 css 没有加载,我确实按照这个链接文本,但到目前为止没有成功,我确实在公共文件夹中有 css

html html

 <link rel="stylesheet" href="/css/style.css">

js 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();
        })
    });
})

Try clearing cache and hard reload.尝试清除缓存并重新加载。 Click ctrl + shift + i, right click on browser refresh button and select 3rd option.单击 ctrl + shift + i,右键单击浏览器刷新按钮和 select 第三个选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM