Express logs [Object: null prototype] instead of a plain object
[Object: null prototype] { title: 'product' }Short answer
This is not an error. The object really has no prototype, so Node.js labels it when you log it. It comes from Node's querystring parser, which Express uses for form data when extended is false. Switch to extended: true, or check keys with Object.prototype.hasOwnProperty.call().
Fix it fast
1Find out which cause you have
Print how the object was built. A null-prototype object shows up in the logs and has no toString() or hasOwnProperty().
node -e "const qs=require('node:querystring'); const o=qs.parse('title=product'); console.log(o, typeof o.hasOwnProperty)"2Match what you see, then jump to its fix
What does the error look like?
[Object: null prototype] { title: 'product' }TypeError: obj.hasOwnProperty is not a function
Cause 1 of 2
express.urlencoded() runs with extended: false
1Check
The extended option picks the parser: querystring when false (the default), qs when true. Look at how the middleware is set up.
grep -rn "urlencoded" --include=*.js --include=*.ts .2Fix
Set extended to true if you want the qs parser, which also supports nested objects. If flat data is enough, keep false and use safe key checks.
app.use(express.urlencoded({ extended: true }));
app.post('/products', (req, res) => {
console.log(req.body);
res.sendStatus(204);
});3Verify
Post a form and read the log again.
curl -i -X POST -d 'title=product' http://localhost:3000/productsConfirmed by expressjs.com
Cause 2 of 2
Your own code calls querystring.parse()
1Check
The object returned by querystring.parse() does not inherit from Object, so toString() and hasOwnProperty() are not defined.
grep -rn "querystring" --include=*.js --include=*.ts .2Fix
Do not call methods on the result. Check keys through the Object prototype instead.
const qs = require('node:querystring');
const parsed = qs.parse('title=product');
if (Object.prototype.hasOwnProperty.call(parsed, 'title')) {
console.log(parsed.title);
}3Verify
Run the file; no TypeError should be thrown.
node parse-test.jsConfirmed by nodejs.org
How do I stop it coming back?
- Treat form data as untrusted and validate every field before use.
- Choose the urlencoded extended setting on purpose, not by copying a snippet.
- Use Object.prototype.hasOwnProperty.call() when you check keys on parsed query data.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
bcrypt.hash throws 'data and salt arguments required'
Error: data and hash arguments required
The bcrypt package throws this when hash gets null or undefined for the password or for the salt.
4 causes, each with a fixBack end
bcryptjs rejects hash() or compare() with Illegal arguments
Error: Illegal arguments: string, undefined
bcryptjs checks the types of its two arguments and, when either is wrong, throws Illegal arguments followed by the typeof of the first and the second.
3 causes, each with a fixBack end
Express warns 'body-parser deprecated undefined extended'
body-parser deprecated undefined extended
The warning appears because urlencoded() was called without the extended option, which body-parser 1.x has warned about since version 1.4.0.
3 causes, each with a fixBack end
Browser blocks a stylesheet or script: MIME type mismatch with nosniff
The Network tab shows the asset URL answered with Content-Type text/html
With X-Content-Type-Options: nosniff the browser accepts a stylesheet only as text/css and a script only as a JavaScript type.
3 causes, each with a fix