Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

469
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda