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

407
Views
I get Error: Can't set headers after they are sent

I am new in node js and I stack with this error longtime. Can someone help me to find a solution! here is the code taht I have written !

router.get('/list',function (req, res, next)
{
   res.render('listaccounts.ejs',{mybalance:mybalance});
 });
 //accounts creation
router.post('/', function(req, res, next) {
var passphrase = req.body.passphrase;
var mybalance=web3.fromWei(web3.eth.getBalance(web3.eth.accounts[0]));
var accountAddress=web3_.personal.newAccount("passphrase",function(error,result){

   if(!error){
    console.log(result);
             }
   else {
    res.render('error.ejs');
       }
    });


res.redirect('/accounts/list');

  });
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

The problem lays in

    if(!error){
    console.log(result);
             }
   else {
    res.render('error.ejs');
       }
    });


res.redirect('/accounts/list');

When it catches else statement, it does render the page, then you call page redirect, but headers were sent during res.render. In short words, you can't render and redirect at the same time

over 4 years ago · Santiago Trujillo Report

0

Just as Jakub said. Also you maty have an async execution problem (you don't know what will execute first, the redirect or the render). I think you could simply:

var accountAddress=web3_.personal.newAccount("passphrase",function(error,result){

   if(!error){
    console.log(result);
    res.redirect('/accounts/list');
   }
   else {
    res.render('error.ejs');
   }
 });
over 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!