This is my code in userController.js
const registerUser = asyncHandler(async (req, res) => { const {name, email, password, phoneNumber} = req.body if(!name || !email || !password || !phoneNumber) { res.status(400) throw new Error('Please add all fields') } res.json({ message: 'Register user'}) })
2
I have a simple CRUD in Node JS and use Mongoose. Why is postman still showing a 400 bad request when POSTing?
It is working now when sending thru the 'Body'.
You’re passing in query params in Postman, but in the controller you are accessing the body.
Change one or the other, either by passing in form data in the body of Postman, or by accessing req.params in your controller.
req.params
Click here to cancel reply.
2
Answers
I have a simple CRUD in Node JS and use Mongoose. Why is postman still showing a 400 bad request when POSTing?
It is working now when sending thru the 'Body'.
You’re passing in query params in Postman, but in the controller you are accessing the body.
Change one or the other, either by passing in form data in the body of Postman, or by accessing
req.params
in your controller.