How to set an external variable inside an sqlite3 callback?

Hello, I’m trying to save the values of this sqlite3 query into the table_info variable, but somehow it only works when I type this code on the node console and not when I run it inside a script.

const sqlite3 = require('sqlite3');

const databasePath = './database/database.sqlite';

const db = new sqlite3.Database(databasePath);

const query = 'PRAGMA table_info(url);';

const table_info = [];

let res = db.each(query, (err, row) => {
    if(err){
        throw(err);
    }else {
        collumn = {
            name: row.name,
            type: row.type,
            notnull: row.notnull,
            dflt_value: row.dflt_value,
            pk: row.pk
        };
        table_info.push(collumn);

    }
});

console.log(table_info);
/*
when running inside the node console:
> [
  { name: 'id', type: 'INTEGER', notnull: 1, dflt_value: null, pk: 1 },
  {
    name: 'base_url',
    type: 'TEXT',
    notnull: 1,
    dflt_value: null,
    pk: 0
  },
  { name: 'hash', type: 'TEXT', notnull: 1, dflt_value: null, pk: 0 },
  {
    name: 'creation_date',
    type: 'TEXT',
    notnull: 1,
    dflt_value: null,
    pk: 0
  }
]

when running inside a script:

> []

*/

console.log(res); 
/*
when running inside the node console:
> Database {
  open: true,
  filename: './database/database.sqlite',
  mode: 65542
}

when running inside a script:

> Database {
  open: false,
  filename: './database/database.sqlite',
  mode: 65542
}


*/