Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Why is node-cron failing to update mysql database?

I am using node-cron to update mysql database every minute, node-cron is working fine (as I checked it by logging some data in the console) but its not updating the database. What am I missing?

const cron = require("node-cron");
const db = require("../util/database");

cron.schedule(`* * * * *`, () => {
  db.getConnection((error, connection) => {
    if (!error) {
      connection.query(
        "SELECT some_field from users",
        (err, users) => {
          if (!err) {
            for(let i = 0; i < users.length; i++){
              let some_var = 1;
              let updated_field = users[i].some_field + some_var;
              connection.query(
                "UPDATE users SET some_field= ? WHERE users.id = ?",
                [updated_field, users[i].id],
                (errs, rows) => {
                  if(!errs){
                    // console.log(updated_field);
                  }
                }
              );
            }
            connection.release();
          }
        }
      );
    }
  });
})
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!