Search code examples
javascripthtmlnode.jsexpressmongoose

how to update mongodb document when a button is clicked in html page


im new to backend development.

i have been trying to make a CRUD notes application without using react,ejs etc.

the problem i face now is i am unable to edit document.

what its supposed to do is when edit is clicked on the html page of a document it should redirect to a page where you can edit the note and save it

this is the code i have got after using different methods

this is the express express segment

this is the helper function to generate html helper function

how do i make it to work

i have implemented the delete functionality similarly

express part

express segment

here is the helper function helper function

i have tried various solutions but each of them use a different approach and i end up even more confused. how do i go about this what is the most optimum approach?


Solution

  • You need to await for the helper function to finish, or else it will send back a promise/empty data.

    Do this const html = await generateHTMLForUpdatePage(ele); instead of const html = generateHTMLForUpdatePage(ele);