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

258
Views
express js cannot set res.json before res.redirect

hello im using express module in node JS

res.json({ auth: true, token: token, message: "success" });
res.redirect('/');

i have to send some json data first then redirect ..but i'm getting this error:
node:_http_outgoing:576


throw new ERR_HTTP_HEADERS_SENT('set'); ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
can anyone please help, thank you

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

0

you can include "redirect" as a property within json, for instance :

res.json({ auth: true, token: token, message: "success", redirect : "/whatever/go"});

then, on the client side you can perform the redirecting like this :

fetch(url)
      .then(res => res.json())
      .then(body => window.location.href = body.redirect)
      .catch(err => console.log(err));
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!