I have made a request to the MongoDB database to retrieve some data based on email. My client-side code is functioning correctly. Here's the code snippet:
useEffect(()=>{
const email = user?.email;
// console.log(email)
const url = `http://localhost:5000/services?email=${email}`;
console.log(url)
fetch(url)
.then(res => res.json())
.then(data => setItems(data))
},[user])
The console.log is displaying the expected data.
However, the issue arises on the backend. I attempted to use console.log to retrieve the email and other information, but no output is being displayed—no errors either. Below is the API code that I implemented using Express.js:
app.get('/services',async(req,res)=>{
const email = req.query.email;
console.log(email)
const query = {email:email};
const cursor = serviceCollection.find(query);
const item = await cursor.toArray();
res.send(item);
});