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

147
Views
InternalServerError: Converting circular structure to JSON

I got a problem with my app, anyone can help me ? Here is my code :

static me = async (req, res, next) => { 
        try {
            const returnDB = await user.me(req, res, next);
            res.status(200).json({
                status: true, 
                message: 'This user',
                returnDB
            })
        } catch (e) {
            next(createError(e.statusCode, e.message))
        }
    }

And here is my error :

InternalServerError: Converting circular structure to JSON
    --> starting at object with constructor 'Socket'
    |     property '_writableState' -> object with constructor 'WritableState'
    |     property 'afterWriteTickInfo' -> object with constructor 'Object'
    --- property 'stream' closes the circle
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

A circular reference ossurs when A refers to B and B refers to A (you can add more steps, if you like). That is no problem for JavaScript, but when you try to write such a setting down to JSON, you end up with an eternal loop.

In your case, the object returnDB refers to res

const returnDB = await user.me(req, res, next);

And res gets the JSON assigned that includes returnDB.

res.status(200).json({
    ...,
    returnDB
})

The error message tells you what attribute of which objects exactly refers to which other object.

Probably, you do not want to include the whole returnDB object in the response, but only some specific attribute of the object?

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!