Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


1.4.4 • Public • Published

Best scheduled tweets

npm version CircleCI codecov

An opinionated library to extract the best links from scheduled tweets from a given Twitter account using Hootsuite (as scheduler source) and Facebook (as ranking mechanism).

It can be useful to build bots or automated newsletters.


With NPM:

npm install best-scheduled-tweets

with Yarn:

yarn add best-scheduled-tweets


This library requires Node.js >= 4.3.2. Therefore it can be used safely within AWS Lambda using the Node.js setup.


The library is composed by a programmatic interface that can be used within Node.js applications and an indipendent command line application that runs on Mac and most linux distributions (with Node.js >= 4.3.2 installed).


To import the library in your project you need to do the following:

With ES2015+:

import { bestScheduledTweets } from 'best-scheduled-tweets';

With ES5:

const bestScheduledTweets = require('best-scheduled-tweets').default;

bestScheduledTweets is now a function that can be invoked with an options object as argument to retrieve the best links from scheduled tweets:

const options = {/* ... */};
const bestLinks = bestScheduledTweets(options);

Internally the library will perform several http requests (Twitter API, Facebook API, URL unshortening, metadata retrieval, ...) so the processing might take a while. Be sure your environment can run for more than 10 seconds and be prepared to use caching mechanisms if needed.


The options available are the following:

  • twitterClient (mandatory): a twitter client instance created with the twitter library
  • fbApp (mandatory): a facebook app instance created with the fb library
  • referenceMoment (mandatory): A moment instance representing a start time from which to consider the tweets
  • screenNames (mandatory): An array of twitter usernames
  • maxTweetsPerUser (optional, default 200): The number of maximum tweets to fetch per user (max 200)
  • numResults (optional, default 7): The number of links to keep at the end
  • blacklistedUrls (optional, default []): A set of blacklisted url that will be ignored in case they are fetched by the main process

Command line app

The command line app can be invoked by simply running in your shell:


This program needs to have the following environment variables set:

  • TWITTER_CONSUMER_KEY: a valid Twitter consumer key
  • TWITTER_CONSUMER_SECRET: a valid Twitter consumer secret
  • TWITTER_ACCESS_TOKEN_KEY: a valid Twitter access token key
  • TWITTER_ACCESS_TOKEN_SECRET: a valid Twitter access token secret
  • FACEBOOK_APP_ID: a valid Facebook application id
  • FACEBOOK_APP_SECRET: a valid Facebook application secret
  • TWITTER_SCREEN_NAMES: a list of comma separated Twitter usernames
  • REFERENCE_MOMENT (optional): a date time string representing the starting point for tweets (it will default to one week ago).

In case of success, the command will output the result in JSON format in the console.

.env tip

You can use the file .env~sample available here as a template to store your environment variables. If you copy it into an .env file you can then run:

source .env && best-scheduled-tweets

Sample output

The command will provide an output similar to the following:

    "title": "Google planning AI tools for Pi makers this year",
    "url": "",
    "description": "Google is intending to expand the dev tools available to makers using the Raspberry Pi microprocessor to power their projects this year -- potentially..",
    "image": "",
    "score": 3789
    "title": "RethinkDB: why we failed",
    "url": "",
    "description": "When we announced that RethinkDB is shutting down, I promised to write a post-mortem. I took some time to process the experience, and I can now write about i...",
    "image": "",
    "score": 1022
    "title": "Making Responsive HTML Email Coding Easy With MJML – Smashing Magazine",
    "url": "",
    "description": "MJML is the only framework making responsive email easy. Learn how to create your own responsive email thanks to MJML in this step-by-step tutorial.",
    "image": "",
    "score": 963
    "title": "Shut Up and Take My Money!",
    "url": "/v/33c3-7969-shut_up_and_take_my_money",
    "description": "FinTechs increasingly cut the ground from under long-established banks’ feet. With a \"Mobile First\" strategy, many set their sights on br...",
    "image": "",
    "score": 627
    "title": "A Trip Down The LoL Graphics Pipeline",
    "url": "",
    "description": " #RiotTechBlog",
    "image": "",
    "score": 621
    "title": "Gmail will block .js file attachments starting February 13, 2017",
    "url": "",
    "description": "Gmail currently restricts certain file attachments (e.g. .exe, .msc, and .bat) for security reasons, and starting on February 13, 2017 , we...",
    "image": "",
    "score": 436
    "title": "The Underestimated Power Of Color In Mobile App Design",
    "url": "",
    "description": "This article covers the most important points related to color in apps, and how to choose colors and contrasts for your app that support usability.",
    "image": "",
    "score": 420


Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.


Licensed under MIT License. © Luciano Mammino.




npm i best-scheduled-tweets

Downloadsweekly downloads








last publish


  • avatar