require("dotenv").config();
const Twitter = require("twitter");
const keys = require("./keys");
const T = new Twitter(keys.twitter);
let params = {
screen_name: "TWITTER_NAME",
count: 20
}
function getTweets() {
T.get("statuses/user_timeline", params, gotTweets);
}
function gotTweets(error, data, response) {
if (error) {
console.log("ERROR: " + error);
} else {
let tweetLength = data.length;
for (i = 0; i < tweetLength; i++) {
console.log(JSON.stringify(data[i].text + " --- POSTED ON: " +
data[i].created_at, null, 2))
}
}
}
I am trying to run the function getTweets() in Node.js. I want to essentially run something like: "node app get-tweets" and have it call getTweets() and return the results to me in the terminal. I understand I could just call the function at the end and run node app, but I want to add other functions in the same module like postTweet().