I am quite new to Node JS, I decided to create a small application
The structure of my project is very simple, I have a catalog of books, When I click on the add book button, I process the POST request then add the book to the database, My problem is that when I try to add the book to the database,
I want to reactively update the state of my array to display my new product, but instead I have to close the connection to the server and then zone enable refresh my page, and then I will see my newly added product, At the same time, the status of my POST request is always pending
index.vue
<div v-for="book in books" :key="book._id">
...
fetch("http://localhost:3000/addedBook", requestOptions)
.then(response => response.json())
.then(result => {
console.log(result)
})
.catch(error => console.log('error', error));
index.js
app.post('/addedBook', (req, res) => {
coll.insertOne(req.body, (err, res) => {
if (!err) {
mongoClient.close();
} else {
console.log('error', err)
}
});