req.body.hasOwnProperty is not a function

how to reproduce this issue?'/', function(req, res, next) {
  • run the server
  • use postman to send a POST request with a couple of body parameters.
  • you’ll get:
<!DOCTYPE html>
        <link rel="stylesheet" href="/stylesheets/style.css">
        <h1>req.body.hasOwnProperty is not a function</h1>

req.body.hasOwnProperty is not a function

Why this happening? is this behaviour expected?

Author: Fantashit

2 thoughts on “req.body.hasOwnProperty is not a function

  1. Well, assuming that the above was the only change, then the answer would be that req.body is the result of Node.js core querystring module’s parse function (, which doesn’t inherit from Object:

    Note: The object returned by the querystring.parse() method does not prototypically extend from the JavaScript Object. This means that the typical Object methods such as obj.toString(), obj.hasOwnProperty(), and others are not defined and will not work.

  2. @wesleytodd Ahh! missed it 😅

    So this is the expected behavior. (it would be awesome if it wasn’t. lol )

    Now I can'/', function(req, res, next) {
      req.body = JSON.parse(JSON.stringify(req.body));

    to fix the issue.

Comments are closed.