req.body undefined
See original GitHub issuehere is my code and I used postman in chrome in post verb to add json like {aaa:'bbb'}
but always the result is {}
var express=require('express'),
bodyParser = require('body-parser'),
mongoose=require('mongoose'),
app=express(),
port=process.env.PORT||3000;
var jsonParser = bodyParser.json({ type: 'application/*+json' } );
var productsRouter=express.Router();
productsRouter.post('/add',jsonParser,function(req,res){
res.send(req.body);
});
app.use('/products',productsRouter);
app.listen(port,function(){
console.log('your server is running');
});
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Express.js req.body undefined - Stack Overflow
I read that this problem is caused by the lack of app.use(express.bodyParser()); but as you can see I call it before the routes....
Read more >How to fix "req.body undefined" in Express.js
In this post we will learn how to fix the "req.body undefined" error in Express.js Framework.
Read more >Cannot read property req body undefined in express - YouTube
codercrab #express #body-parserCannot read property req body undefined in express ||Express req body is undefined for post requests.
Read more >node js express req.body undefined - You.com
First time using express, it seem whenever I call req.body in this application it is returning as undefined. Any ideas why? App is...
Read more >How to fix the Express req.body undefined error - Reactgo
In this tutorial, we will learn how to fix the req.body undefined error in express. Consider, we have a /users route in our...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
thank you very much for your reply here is my code after editing
and I sent json
{aaa:'bbb'}
and result still empty{}
thanks for your help