Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

463
Views
CSS not linking to Ejs file

I believe this is the correct way to link the css to the ejs file, however it's still not working. You can see how all my folders are arranged in the pictures provided.pic1 pic2 enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

In your server.js file, use this line instead of the one you have :

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

The line above tells express where to find public assets. With this, evrytime you write / in a ejs file, you are already in the public folder.

You will for example link your css file like so (I assume your css styles are inside public/css/styles.css):

<link href="/css/styles.css" rel="stylesheet">
about 4 years ago · Juan Pablo Isaza Report

0

your problem is not with the link tag in your Ejs file. the problem is with defining the path for your file inside the server.js file

the solution is to use static method inside the express 'use' middleware as the following:

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

this means that you are telling express where to find and serve static files.

for linking the css file, all you have to do inside your Ejs file is to add a link tag as follows:

<link href="/css/styles.css" rel="stylesheet" type="text/css">
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!