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

162
Visualizações
forEach javascript

I have this fetchTweets function which is called with cron every 10secs, and my problem is that newTweets variable is not incrementing, in console i am getting 0. As you can see i initialized variable and gave it initial value 0, and its being incremented in forEach and then returned.

fetchTweets: async () => {
        let dt = dateTime.create()
        const time = dt.format('Y-m-d H:M:S')

        let users = await userControl.getAllUsers('WHERE isActive = ?', 1)

        let twitterUsers = Object.values(JSON.parse(JSON.stringify(users)))
    
        var newTweets = 0
        twitterUsers.forEach(async (user) => {
            twitterResponse = await twitter.get(`users/${user.twitter_id}/tweets`, { max_results: 10 })

            twitterResponse.data.forEach(async (tweet) => {
                const tweetCheck = await SQL('SELECT COUNT(id) as cn FROM twitter_tweets WHERE tweet_id = ?', [tweet.id])
                if(tweetCheck[0].cn == 0) {
                    newTweets++
                    const t = [user.twitter_id, tweet.id, tweet.text, time]
                    await SQL('INSERT INTO twitter_tweets SET twitter_id = ?, tweet_id = ?, tweet_text = ?, added_at = ?', t)
                }
            })
        })
        return newTweets
    }
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