0

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.

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();
        })
    });
})
2
  • How is the HTML page containing this <link> loaded? Also via the express server? Do you have errors in the console/network? Commented Apr 18, 2021 at 10:49
  • <link rel="stylesheet" href="/css/style.css">, and no error in the console Commented Apr 19, 2021 at 9:23

1 Answer 1

0

Try clearing cache and hard reload. Click ctrl + shift + i, right click on browser refresh button and select 3rd option.

Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately still the same, gonna try to replicate the project and see what can be later

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.