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

118
Visualizações
async function inside new async function

I need to fetch data from Mongo db using mongoose then send some request using node-fetch. So I created below async function

async function mainThree() {

    await ProvinceList.find({}).then((data) => {

        data.forEach((provience) => {
            console.log(provience.id)
            let response = await fetch(`https://xxxx.com/api/getSubAddressList?addressId=${provience.id}`, {
                "headers": {
                    "accept": "application/json, text/plain, */*",
                    "accept-language": "en-US,en;q=0.9,si;q=0.8",
                    "cache-control": "no-cache",

                },
                "referrer": "https://www.xxxx.com/",
                "referrerPolicy": "strict-origin-when-cross-origin",
                "body": null,
                "method": "GET",
                "mode": "cors"
            });

            let datalist = await response.json();


            CityList.insertMany(datalist.module);

        });


    });



}

but when I running code I am getting

**SyntaxError: await is only valid in async function**

I need to know How I run Async function insite Async function

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In this case, you're using the await inside of the function passed to forEach. You need to make that function async.

data.forEach(async (province) => ...

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