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

221
Views
Getting `[Object: null prototype]` with Fastify, expected values are undefined

I register the following plugins on server boot:

const registerPlugins = (app) => {
    app.register(require('fastify-cors'), {
        origin: '*',
        methods: ['POST', 'PUT', 'DELETE'],
        credentials: true,
    });

    app.register(require('fastify-static'), {
        root: path.join(__dirname, 'client', 'build'),
    });

    app.register(require('fastify-helmet'), { contentSecurityPolicy: false });
    app.register(require('fastify-multer').contentParser);
    app.register(require('fastify-formbody'));
    app.register(require('fastify-qs'), {});
};

And I have a simple route that looks like this:

fastify.post('/login', {
    handler,
})

And my handler looks like this:

const handler = async (req, reply) => {
    try {
        const { email, password } = req.body;

        console.log('req.body', req.body);
        console.log('email', email);
        console.log('password', password);

        return reply.send();
    } catch (err) {
        return reply.code(500).send({ error: err });
    }
};

email and password are undefined for some reason, but when I print req.body, it gives me this:

req.body [Object: null prototype] {
   '{"email":"asdasd","password":"asdas"}': ''
}

What am I doing wrong here?

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

0

Hello Juan, I had the same problem.

I didn't find a clean way get rid of it. To avoid [Object: null prototype] I parsed again the body.

JSON.parse(JSON.stringify(req.body)) // => {"email":"asdasd","password":"asdas"}
about 4 years ago · Antoine Pertoldi 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!