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

501
Visualizações
browser won't load css stylesheet for my local website using express and node

enter image description here

enter image description here

And the app.js screenshot: enter image description here

I tried every possible combination of href and express.static(""); adresses. I either get a response from a browser saying browser wont allow me to load local files or I get this: enter image description here

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Since the folder name public is already contained in the URL of your stylesheet, you must write

app.use("/public", express.static("D:\\Igor\\Desktop\\Angela\\todolist-v1\\public"));

Note also that backslashes must be doubled in Javascript strings.

With your current code, the stylesheet is looked up at D:\Igor\Desktop\Angela\todolist-v1\public\public\css\styles.css, where it does not exist. This leads to an HTML error page ("Cannot GET ..."), hence the browser complaint about the wrong mime type.

over 4 years ago · Santiago Trujillo Relatório

0

. If you run the express app from another directory, it’s safer to use the absolute path of the directory that you want to serve.

Have you installed "path" module??

If not first install it.

  1. Do

    const path= require('path')

  2. To use a static directory in your app do,

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

  1. Now to access assets under public folder in any directory use,

    public/css/style.css

over 4 years ago · Santiago Trujillo 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