I am trying to store the id's from a tweet for later, using the following code:
let twit = require('twit');
let config = require('./config.js');
const T = new twit(config);
let retweetIDs = [];
const promise = T.get('statuses/user_timeline', {screen_name: 'someusername', count: '1'});
promise.then(res =>{
let id = res["data"][0]["id"];
retweetIDs.push(id)
});
console.log(retweetIDs)
What the console.log() returns is an empty array [].
While I understand that javascript is asynchronous so the log statement gets executed before a response is returned from the GET request, that is, why it is happenning, I don't understand how to fix it. Any help will be appreciated.