title: Wait a Promise to finish in an express function
body: <p>I have a post call in Express which needs to be validated, so I created a javascript file called "validator.js" to check the passed values before proceeding. One of the methods in "validator.js" needs to do an axios call, but it obviously needs time before fullfill data. So I solved with async/await like this</p>
  
  <pre><code>router.post("/add_to_favorites", passport.authenticate("local"), async(req, res) =&gt; 
      { let validation = await validateMedia(req.body);
  
  if (validation.error) {
      return res.status(400).json(validation.message);
     }
  </code></pre>
  
  <p>"validateMedia" is the function which calls validator.js.
  <hr>
  <strong>What is the best way to handle this axios async call considering the following code?</strong></p>
  
  <p><strong>Express</strong></p>
  
  <pre><code>router.post("/add_to_favorites", passport.authenticate("local"), (req, res) =&gt; 
      { let validation = validateMedia(req.body);
  if (validation.error) {
      return res.status(400).json(validation.message);
    }
  }
  </code></pre>
  
  <p><strong>validator.js</strong></p>
  
  <pre><code>const validateMedia = data =&gt; {
    if (data.mediaType !== "movie" &amp;&amp; data.mediaType !== "serie") {
      return {
        error: true,
        message: "Media type is not valid"
      };
    }
  
    if (data.mediaType === "movie") {
      axios.get(`/${data.mediaType}/${data.mediaId}`).then(response =&gt; {
        if (data.mediaTitle === response.data.title) {
          return { error: false, message: "Success" };
        }
        return { error: true, message: "Failed" };
      });
    }
  return { error: false, message: "Checked values" };
  }
  </code></pre>