Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
Wait for my files to be created. JS (express-fileupload)

Express-fileupload has a function that allows to move the .mv() file, what I am looking for is to wait for it to finish so I can proceed with the next task.

NPM: https://www.npmjs.com/package/express-fileupload

CODE

console.log("Starting the loop")
for (const element of _sources) {
  const file = req.files[element];
  if (file !== undefined) {
    const _mime = mimesList.filter((v) => v.mimetype === file.mimetype);
    if (_mime.length === 0) {
      //... exec
    } else {
      console.log("Start moving the file")
      const previewPath = _path + new tokenGenerator().generate() + element + _mime[0].extension;
      await file.mv(previewPath, function (err) {
        if (err) {
          //!make error
        }
        req.files[element].preview = previewPath;
        console.log("No errors")
      });
      console.log("I have finished moving the file.")
    }
  } else {
    //.. exec
  }
}
console.log("Ending the loop")

current output

Starting the loop
Start moving the file
I have finished moving the file.
Start moving the file
I have finished moving the file.
Start moving the file
I have finished moving the file.
Ending the loop
No errors
No errors
No errors

expected output

Starting the loop
Start moving the file
No errors
I have finished moving the file.
Start moving the file
No errors
I have finished moving the file.
Start moving the file
No errors
I have finished moving the file.
Ending the loop
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda