title: Call a function is JavaScript that calls a promise function and returns the result to the original function
body: <p>I have two functions (One function within the controller and oen function in a service). I want to call the service function from the controller function. After calling teh service function this function calls a database function (using Sequelize).</p>
  <p>Controller:</p>
  <pre><code>exports.getMilestoneById = async (req, res, next) =&gt; {
      const milestoneId = req.params.milestoneId;
      try{
      milestoneService.getMilestoneById(milestoneId)
      .then(mielstone =&gt; {
          console.log(&quot;Milestone in tehn: &quot; + mielstone)
      });
      console.log(&quot;Milestone: &quot; + milestone);
      res.status(200).json({message: 'Milestone fetched', milestone: milestone});
      } catch (error){
          if (!error.statusCode){
              error.statusCode = 500;
          }
      }
  }
  </code></pre>
  <p>Service:</p>
  <pre><code>exports.getMilestoneById = async (milestoneId) =&gt; {
  
  Milestone.findByPk(milestoneId)
  .then(milestone =&gt; {
      console.log(&quot;In Service: &quot; + milestone)
      return milestone.get();
  })
  .catch(err =&gt; {
      console.log(&quot;Error&quot; + err);
  });
  </code></pre>
  <p>}</p>
  <p>The problem: I don't get a milestone back.</p>