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

305
Visualizações
NodeJS - res.sendFile gives html code but not loading/rendering that html

I am very new to NodeJs. I am using express module in NodeJS and trying to load html files through sendFile command. While doing it my first sendfile command works well, however it doesnt work well for second sendFile command. Can anyone please let me know whats going wrong here?

 var express = require('express');

 var app = express();
 var path = require('path');

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

 app.get('/', function(req, res){
   res.sendFile(path.join(__dirname, 'public/index.html'));
 });

 app.get('/unpack', function(req, res){
  res.sendFile(path.join(__dirname, 'public/main.html'));
 });

In the above code the below line works well

 res.sendFile(path.join(__dirname, 'public/index.html'));

Problem lies with

 res.sendFile(path.join(__dirname, 'public/main.html'));
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Thanks @warl0ck and @robertklep for your response. As @robertklep mentioned in the comments section my problem was that I was using AJAX to call /unpack hence I was getting the response as html code. This helps me to understand the problem and I will change AJAX to something else.

Thanks @warl0ck and @robertklep again!!!

-kt

about 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