title: My NodeJs code is returning undefined value
body: <p>This is the code that i have written,</p>
  <pre><code>function getAllTasksToThatProjectType(typeId){
      let storeTaskIds = [];
      let projectTypeTasks = [];
      let returnVar = new Array();
      ProjectType.findOne({ _id: typeId })
      .exec((error, projectType) =&gt; {
          // if(error) return res.status(400).json({ error })
          if(projectType){
              projectType.tasks.map(tsk =&gt; storeTaskIds.push(tsk.taskId))
              ProjectTask.find({ })
              .exec((error, projectTask) =&gt; {
                  // if(error) return res.status(400).json({ error })
                  if(projectTask){
                      storeTaskIds.forEach(function(tID){
                          projectTask.forEach(function(tsk){
                              if(JSON.stringify(tsk._id) == JSON.stringify(tID) || JSON.stringify(tsk.parentId) == JSON.stringify(tID))
                                  projectTypeTasks.push(tsk)
                          })
                      })
                      // Here would be the api return statement.
                      return projectTypeTasks;
                  }
              })
          }
      })
  }
  
  
  
  const taskForPType = getAllTasksToThatProjectType(req.body.typeOfProject)
  </code></pre>
  <p>If i call the function like this, it will set the value of <code>taskForPType</code> to <code>undefined</code>.
  I have to do this without a callback function. Any suggestions on how i could i achieve it.</p>