windows 10 pro office 2019 pro office 365 pro windows 10 home windows 10 enterprise office 2019 home and business office 2016 pro windows 10 education visio 2019 microsoft project 2019 microsoft project 2016 visio professional 2016 windows server 2012 windows server 2016 windows server 2019 Betriebssysteme office software windows server https://softhier.com/ instagram takipçi instagram beğeni instagram görüntüleme instagram otomatik beğeni facebook beğeni facebook sayfa beğenisi facebook takipçi twitter takipçi twitter beğeni twitter retweet youtube izlenme youtube abone instagram

async keyword not working on function using node js

Asked By: Anonymous

I don’t know why i am getting this error

  • uncaughtException: await is only valid in async function

as i am using async keyword at getChild function still i am getting this error

  • my code:
async function filterFile(folderPath) {
  try {
    wantExt = [".jpg"];
    let parts;
    const paths = await checkFileLoc(folderPath, 3);
    const otherFiles = [];

    for (const filePath of paths) {
      parts = filePath.split("/");
      let splitFileName = parts[parts.length - 1].split(".");
      if (wantExt.includes(`.${splitFileName[splitFileName.length - 1]}`)) {
        otherFiles.push(filePath);
      }
    }
    let ignoreFile = otherFiles.filter((x) =>
      x.endsWith("_bio.jpg")
    );
    let test = otherFiles.filter((x) => !ignoreZipFile.includes(x));
    return { test };
  } catch (error) {
    console.log("error:", error);
  }
}

async function getChild(parents) {
  return new Promise(function (resolve, reject) {
    Shop.findAll({
      where: {
        shop_no: parents.id,
      },
      attributes: ["id", "name"],
    })
      .then((children) => {

        let gotValue= await filterFile(children);
        console.log(gotValue);

        resolve(children);
      })
      .catch(function (err) {
        reject(err);
      });
  });
}

and if i remove async from the function then I am getting gotValue as promise don’t know how to get value


Solution

Answered By: Anonymous

Try adding async to callback function in findAll

async function getChild(parents) {
  return new Promise(function (resolve, reject) {
    Shop.findAll({
      where: {
        shop_no: parents.id,
      },
      attributes: ["id", "name"],
    })
      .then(async (children) => { // Add it here

        let gotValue= await filterFile(children);
        console.log(gotValue);

        resolve(children);
      })
      .catch(function (err) {
        reject(err);
      });
  });
}

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno
524 Origin Time-out

524 Origin Time-out


cloudflare-nginx