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

449
Visualizações
Javascript - Perform several functions in a row && Error: ENOENT: no such file or directory

I have created in my project several separate functions in separate files that I import with module.exports.$functionName

I then compile everything in an index.js file. This is the problem. The first function allows to download a file, without which the two other functions can't work. I tried to use the promises to wait for the download, but the file does not download and this error appears:

Error: ENOENT: no such file or directory

Here is the code, I specify that each function works when you run them independently:

const mt = require("./mainTweet"); // from mainTweet.js 
const rp = require("./Reply"); // from Reply.js
const od = require("./getcsv") // from getcsv.js

function Download() {
  return new Promise((resolve) => {
    od.onDownload();
    resolve();
  });
}

function firstTweet() {
  return new Promise((resolve) => {
    mt.getData()
    resolve();
  });
}

function secondTweet() {
  rp.Reply();
}

async function Launch() {
  await Download();
  await FirstTweet();
  Reply();
}

Launch();
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Since you answered in a comment that od.onDownload, mt.getData and rp.Reply are async, the problem is that you do not await them.

When you do this:

od.onDownload()
resolve()

onDownload() will run and return a promise immediately and then you resolve your own promise. This means that onDownload has not yet resolved (or thrown). You should instead await each call. You could simplify your whole code to this:

const mt = require("./mainTweet"); // from mainTweet.js 
const rp = require("./Reply"); // from Reply.js
const od = require("./getcsv") // from getcsv.js

async function Launch() {
  await od.Download();
  await mt.getData();
  rp.Reply()
}

Launch();
about 4 years ago · Juan Pablo Isaza Relatório
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