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

105
Views
Express ignores response.send() call

I have a simple server. Code is explained below:

const express = require("express");
 
const app = express();
 
app.set("view engine", "hbs");
 
app.get("/about-me", function(_, response) {
    response.render("about_me.hbs");
});
app.get("/", function (_, response) {
    response.render("index.hbs");
});
app.all(/.*/, function (_, response) { // 404 page
    response.sendStatus(404); // set status code to 404
    response.send("<h1>404 Not Found</h1>"); // send a body
}
app.listen(3000);

But when I opened http://localhost:3000/not-exist , there was "Not Foun<" text. Why it's happening?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can't send two responses to a single request.

Use sendStatus or send.

If you want to control the status code when you use send, use status.

about 4 years ago · Juan Pablo Isaza 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!