Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

303
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!