npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tweetserver

v0.0.6

Published

A server to proxy and cache requests to the Twitter v1.1 REST API

Downloads

15

Readme

TweetServer

TweetServer is a simple Node.js app for querying and caching responses from the Twitter REST API (version 1.1). It runs as a standalone server (built on Express) and effectively proxies any requests over to the API.

Why should you use it?

  • It handles the Twitter API rate limits for you, ensuring that the returned data is as up-to-date as possible without getting your application blacklisted for making too many requests.

  • It means you can communicate with the API from your front-end JavaScript with AJAX. This is difficult with the latest (1.1) version of the API since almost all requests have to be authenticated.

  • You can use it to display Tweets in your own style, rather than having to use one of the pre-built Twitter widgets.

  • Supports JSONP so you should be able to run your server anywhere and still make AJAX requests to it.

Setup

TweetServer is available as through npm. That's the recommended method of installation. Just install it as a global module:

npm install -g tweetserver

Configuration

TweetServer assumes you already have a Twitter application. If you don't, you can easily create one.

You'll need various credentials from Twitter to setup your Tweet Server. They can be found on the details page for the Twitter application you want to use. Sign in at the URL linked to above and make a note of your consumer key, consumer secret, access token and access token secret.

TweetServer will look for a configuration file on startup. Create a file named .tweetserverrc in your home directory, or the directory to which TweetServer was installed (any of the parent directories, including the root directory, will work too).

The .tweetserverrc file contains simple JSON in the following format:

{
    "port": 1234,
    "auth": {
        "access-token": "xxxxx",
        "access-secret": "xxxxx",
        "consumer-key": "xxxxx",
        "consumer-secret": "xxxxx"
    }
}

If you'd prefer not to store your API keys in a file, you can also specify them at startup with the following command line arguments:

| Short option | Long option | Value | | ------------- |---------------------| --------------------------------------| | -k | --access-token | Your Twitter API access token | | -a | --access-secret | Your Twitter API access token secret | | -c | --consumer-key | Your Twitter API consumer key | | -s | --consumer-secret | Your Twitter API consumer secret | | -p | --port | The port on which the server will run |

If you specify command line arguments and have a configuration file, the command line arguments will override the configuration file. You can run the server with any number of the arguments.

Running the server

If you installed TweetServer via npm with the -g (global) option, you will have a tweetserver command available to you. Just run that from anywhere (optionally with any of the command line arguments detailed above) to start the server:

tweetserver

You will see a message that tells you the server is now running. At this point you'll be able to open a browser and check that everything's working properly. Assuming your Tweet Server is running on localhost on port 3456 (which is the default), you can visit:

http://localhost:3456/statuses/user_timeline?screen_name=james_allardice

If you've used the Twitter API much before, you may have noticed that everything after the port in that URL is simply the same as what you would usually use when calling the API directly. Currently, all Twitter API v1.1 methods that support HTTP GET requests are supported.

Keeping the server running

I highly recommend using the brilliant "forever" module to keep your server up and running all the time.