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

221
Visualizações
Node.js express can not get the css and js file

Here is my main.ts file I can not get my css and js file enter image description here

import express from 'express';
import {Request,Response} from 'express';
import expressSession from 'express-session';
import path from 'path';

const app = express();


// set session 
app.use(expressSession({
    resave:true,
    saveUninitialized:true
}));

// teach the server to go to the main page//
app.get("/", (req: Request, res: Response) => {
  res.sendFile(path.resolve(__dirname, "../frontend/public/index.html"));
});



app.use(express.static('public'))

const PORT = 8080;

app.listen(PORT, () => {
    console.log(`Listening at http://localhost:${PORT}/`);
});

And here is my file structure enter image description here here is my html file enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

First things first, you shouldn't post the app secret in a public forum. Second, can you post your index.html file? Chances are it incorrectly loads the JS and CSS files. Third, you can import default and class exports from a package in one line. Change

import express from 'express';
import {Request,Response} from 'express';

to

import express, { Request, Response } from 'express';
about 4 years ago · Juan Pablo Isaza Relatório

0

seems from the screenshot that your public folder is empty. you seem to have the index.html and other files in your frontend folder and not in the public folder. your index.js and your index.html are on the same level. so your path does not resolve correctly if you resolve it from the index.js file

from which file are you resolving the path? from index.js or main.ts?

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