title: Exit the process when multiple async operations completed
body: <p>I want to exit node process when all data will be processed (fetch data, http request with axios and update data). When I run my script by typing <code>node script.js</code> it never ends. Where should I use process.exit() in my script to be sure all data has been processed? Script below:</p>
  
  <pre><code>Keyword.find({
          images: {
              $eq: []
          }
      })
      .limit(8)
      .exec((err, keywords) =&gt; {
          keywords.forEach((keyword) =&gt; {
              console.log(keyword.body);
              axios.get('https://www.example.com/?q=' + encodeURIComponent(keyword.body))
                  .then(function (response) {
                      const dom = new JSDOM(response.data);
                      let items = dom.window.document.querySelectorAll('div.item');
                      let images = [];
                      items.forEach(((item) =&gt; {
                          let url = item.querySelector('a.thumb').href;
                          let source = item.querySelector('a.tit').href;
                          let description = item.querySelector('div.des').innerHTML;
                          images.push({
                              url,
                              source,
                              description
                          });
                      }));
  
                      Keyword.findByIdAndUpdate({
                          _id: keyword._id
                      }, {
                          $set: {
                              images
                          }
                      }, (err2, result2) =&gt; {
                          if (err2) console.log(err2);
                          console.log(result2);
                      });
                  })
                  .catch(function (error) {
                      console.log(error);
                  });
          });
      });
  </code></pre>