Get latest tweet by Github Username - Promises

A simple demo to use superagent and rss parser to get the latest tweet of a person by Github username.

by Geshan Manandhar

HTML

<script src="https://unpkg.com/[email protected]/superagent.js"></script>
<script src="https://unpkg.com/[email protected]/dist/rss-parser.min.js"></script>

JavaScript

const request = window.superagent;
const parser = new RSSParser();
const CORS_PROXY = 'https://cors-anywhere.herokuapp.com/';
let twitterUser = '';

request
  .get('https://api.github.com/users/abraham')
  .set('Accept', 'application/json')       
  .then(res => {
  	console.log('Twitter Username: ', res.body.twitter_username);
  	return res.body.twitter_username;
  }).then(twitterUserName => {
  twitterUser = twitterUserName;
  return parser.parseURL(`${CORS_PROXY}https://nitter.net/${twitterUserName}/rss`);
  })
  .then(feed => {
  	console.log(`The last tweet by ${twitterUser} is - ${feed.items[0].title}`);
  })
  .catch(err => {
  	console.log(`Error occurred ${e.message}`, e);
  });

console.log('This would log first');