0

the following code is part of my router code:

.get(function(req, res) {

    var project = Project.findOne({ 'projectName': req.params.id }, function (err, project) {

        if (err) return handleError(err);

    }); 

    console.log('found project: ' + project.projectName);

However, the code above returns 'undefined' on the server side. Can someone help?

Thanks!

Trung Tran
  • 13,141
  • 42
  • 113
  • 200
  • what happens if you just console.log('project'); is that undefined? – Chris Hawkes Nov 12 '15 at 16:43
  • 1
    It's because `findOne()` is asynchronous, put the `console.log('found project: ' + project.projectName);` inside the callback, after the `handleError(err)` line. – chridam Nov 12 '15 at 16:48

0 Answers0