My project is to basically create users in a database and store information about exercise. I'm using mongodb and express.
I am struggling to understand the way the course was teaching me, which was with functional expressions and using the done() callback.
app.post('/api/users', (req, res)=>{
const userRequest = req.body.username;
if(userRequest === '' || undefined) return;
console.log('requesting to create user ' + userRequest);
const findByName = (userRequest, done) => {
User.find({user: userRequest}, (err, userFound)=>{
if(err) return console.error(err);
console.log(`${userRequest} already exists`);
done(null, userFound);
});
};
})
here so far I'm just trying to begin by creating a user. I want to first check if that user already exists. How do I check the results of this function? I've written it the way the course taught me I just don't understand it. I don't know what the done() callback does.