Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda