title: waiting the ending loop of promise?
body: <p>How could I wait for the end of the loop, get the images' paths,
  and then inject it into the query?</p>
  <p>Before data creation:</p>
  <pre class="lang-js prettyprint-override"><code>let images = [];
  for ( const file in files ) {
      fs.writeFileSync(  __dirname + '/'+file+'.jpg', files[file].data );
      uploads( __dirname + '/'+file+'.jpg', 'smoothies/recipes' )
          .then( ( resolve ) =&gt; {
              images.push('https://res.cloudinary.com/###########' + resolve.public_id) ;
          } )
          .then( () =&gt; {
              console.log('images uploaded here path =&gt; ', images);
              fs.unlinkSync(  __dirname + '/'+file+'.jpg' );
              console.log('file removed here ');
              //file removed
          })
          .catch( ( error ) =&gt; {
              res.status( 500 ).send( {
                  message:&quot;failure tu upload the image&quot;,
                  error,
              } );
          } );
  }
  
  Recipe.create( { name, ingredients, steps, images } )
      .then( async () =&gt; {
          let recipes = await Recipe.find();
          res.status( 201 ).json( recipes );
      } )
      .catch( ( error ) =&gt; {
          res.status( 500 ).send( {
              message:&quot;failure to create the Recipe with images&quot;,
              error,
          } );
      } );
  </code></pre>
  <p>I can't find the solution.</p>
  <p>Thanks.</p>