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

@humanwhocodes/tweet

v1.0.1

Published

A CLI for tweeting out messages

Downloads

31

Readme

Tweet CLI

by Nicholas C. Zakas

Node CI

If you find this useful, please consider supporting my work with a donation.

Description

A simple CLI for sending tweets. This is intended for use in CI systems such as GitHub actions in order to enable to Twitter notifications of important events.

Usage

You must have Node.js to use this package.

To start, you must have a registered Twitter application.

Next, define four environment variables:

  • TWITTER_ACCESS_TOKEN_KEY - your access token
  • TWITTER_ACCESS_TOKEN_SECRET - your access token secret
  • TWITTER_CONSUMER_KEY - your consumer API key
  • TWITTER_CONSUMER_SECRET - your consumer API secret

The CLI will not work without these environment variables. All of these values come from your Twitter application.

Then, you can run the CLI and pass a message on the command line using npx:

$ npx @humanwhocodes/tweet "Hello from the command line!"

If successful, the CLI will output the response from Twitter.

Setting Twitter API version

By default, Tweet uses v2 of the Twitter API. If you'd like to use v1.1 of the Twitter API instead, set the TWITTER_API_VERSION environment variable to v1.

Testing with dotenv

If you'd like to test with dotenv, define an additional environment variable TWEET_DOTENV=1 before executing the CLI. This will cause a local .env file to be read before executing.

Using in a GitHub Workflow

Be sure to set up GitHub secrets for each environment variable. Then, you can configure a job like this:

jobs:
  tweet:
    name: Tweet Something
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-node@v3
        with:
          node-version: 18
      - run: 'npx @humanwhocodes/tweet "Your tweet text"'
        env:
          TWITTER_CONSUMER_KEY: ${{ secrets.TWITTER_CONSUMER_KEY }}
          TWITTER_CONSUMER_SECRET: ${{ secrets.TWITTER_CONSUMER_SECRET }}
          TWITTER_ACCESS_TOKEN_KEY: ${{ secrets.TWITTER_ACCESS_TOKEN_KEY }}
          TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}

Developer Setup

  1. Ensure you have Node.js 12+ installed
  2. Fork and clone this repository
  3. Run npm install
  4. Run npm test to run tests

Troubleshooting

Console says "Required environment variable 'TWITTER_ACCESS_TOKEN_KEY' is an empty string."

You haven't setup the correct environment variables for Tweet CLI. Double check that you don't have any misspellings in your environment variable settings.

GitHub Actions console says "Required environment variable 'TWITTER_ACCESS_TOKEN_KEY' is an empty string."

You're probably trying to use the Tweet CLI during the pull_request event. This won't work because secrets are not available when a pull request is from a fork. Try using the pull_request_target event instead. (More information)

License and Copyright

This code is licensed under the Apache 2.0 License (see LICENSE for details).

Copyright Human Who Codes LLC. All rights reserved.