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

1.6K
Views
node:internal/errors:464 ErrorCaptureStackTrace(err); ^ Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

Why do I keep getting this error? Iam using nodejs, and am not that familiar with backend programming, so I cant really know whats going on, If anyone is fimiliar with this error or knows what causing, PLEASE HELP MEπŸ™πŸ™πŸ˜Œ

Here is my code??

    async function verify() {
        const ticket = await client.verifyIdToken({
            idToken: token,
            audience: CLIENT_ID,  // Specify the CLIENT_ID of the app that accesses the backend
        });
        const payload = ticket.getPayload();
        const userid = payload['sub'];
      }
      verify()
      .then(()=>{
          res.cookie('session-token', token);
          res.send('success')
      })
      .catch(console.error);

})

const stripe = require('stripe')(process.env.STRIPE_PRIVATE_KEY)


app.post("/create-checkout-session", async (req,res)=>{
    try{
const session = await stripe.checkout.sessions.create({
payment_method_types:['card'],
mode:'payment',
line_items: req.body.items.map(item=>{
    
    return{
        price_data:{
            currency:item.currency,
            product_data:{
                name:item.name
            },
            unit_amount: item.priceInCents,
        },
        quantity:item.quantity
    }
}),
success_url:`${process.env.SERVER_URL}/success.html`,
cancel_url:`${process.env.SERVER_URL}/cancel.html`
})
res.json({url:session.url})
    }catch(e){
res.status(500).json({error:e.message})
    }
    
    res.json({url:'Hi'})
})````
about 4 years ago Β· Juan Pablo Isaza
1 answers
Answer question

0

you are trying to set Http headers after they are sent.

This error is occuring because your code is using res.json in both try and catch blocks. It means res.json() will be executed no matter error occurs or not. Which sends json response.

Then you are using res.json outside the try/catch blocks, it means you're trying to send response after it is already sent.

And that is causing this error.

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!