I'm working on a project where I need to display the user data into the HTML web-page. For that, I have already created the POST and GET methods for API. I don't know how do I display the data on the webpage.
PS: I'm not allowed to use frameworks like angular or react. I have to do it with MEN stack.
POST method:
router.post('/adduserdata', (req, res) => {
bcrypt.hash(req.body.password, 10, (err, hash) => {
if (err) {
res.json({
error: err
});
}
else {
const user = new userdata({
name: req.body.name,
email: req.body.email,
password: hash,
mobile_no: req.body.mobile_no,
data_of_birth: req.body.data_of_birth
})
try {
user.save()
res.json({
message: "User Created.."
});
}
catch (err) {
res.send('Error');
}
}
});
});
GET method:
router.get('/getuserdata', async (req, res) => {
try {
const user = await userdata.find().select("name email mobile_no data_of_birth")
res.json(user)
}
catch (err) {
res.send('Error ', err)
}
});