Jump to content

css not loading even though there're no errors and it's linked correctly in ejs

Person_125
Go to solution Solved by Person_125,

It was just missing 

rel="stylesheet"

and a / before the path

 

so, I'm trying to link a css file to an ejs file but it's not working, and I think I'm linking them correctly:

<head>
<title>Acres & Karats Calculator</title>
<base href="/">
<link type="text/css" href="css/Acres_and_Karats_Calculator.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Titillium+Web:400,700&display=swap" rel="stylesheet">

 

and i specified the public directory to be used in express:

let express = require("express"),
    app     = express();

app.use("/public", express.static(__dirname + "/public"));

app.get("/", (req, res) => {
    res.render("Acres and Karats Calculator.ejs")
});

app.listen("3000", () => {
    console.log("Server started!");
});

and there are no errors in the console at all and the css is not loaded

file structure:

  • app.js
  • views
    • pubilc
      • css
        • Acres and Karats Calculator.css
Link to comment
Share on other sites

Link to post
Share on other sites

At first glance I'm fairly sure you're telling Express to serve from the wrong directory:

- app.js

- public (you've set it to look here)

- views 

     - public (instead of here)

           - css

 

I think the static line should be

app.use("/public", express.static(__dirname + "/views/public"));

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Haas_ said:

At first glance I'm fairly sure you're telling Express to serves from the wrong directory:

- app.js

- public (you've set it to look here)

- views 

     - public (instead of here)

           - css

 

I think the static line should be


app.use("/public", express.static(__dirname + "/views/public"));

 

Thanks for your reply, but that didn't work

Link to comment
Share on other sites

Link to post
Share on other sites

It was just missing 

rel="stylesheet"

and a / before the path

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×