Ok thanks,
When I try to send data through postman.
And then I try to find that data inside req object. I’m not getting anything.
When I do console.log(req.body). it returns a empty object
This is my code
router.post('/items', async (req, res) => {
const {name, image} = req.body;
const {secret_key} = req.headers;
// Authanticating the user
if(secret_key !== process.env.MY_SECRET_KEY) {
return res
.status(403)
.send({error: 'You are not allowed to add data!😠'});
}
console.log(req)
Checking data values
if(!name || !image) {
return res
.status(422)
.send({error: 'There is no name and image'});
}
try {
const item = new Item({name, image});
await item.save();
res.send(item);
} catch (error) {
res.status(422).send({error: error.message});
}
})