Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

301
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda