client.get
is asynchronous
This code is working, then you have to manage your code to wait for asynchronous response.
client.get('statuses/user_timeline', function(error, tweets, response){
if(error) throw error;
console.log(tweets)
});
If you have some code after client.get, you should do that
before :
var userTweets = client.get(..., function() {});
// do some code
console.log(userTweets);
after :
client.get(....., function(error, tweets) {
...
otherCode(tweets);
});
function otherCode(userTweets) {
// do some code
console.log(userTweets);
}
I suggest you to read this answer : https://stackoverflow.com/a/11233849/5384802 to understand asynchronous code.