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

node-ttv

v2.1.0

Published

A Node.js wrapper for Twitch.tv's helix API.

Downloads

45

Readme

node-ttv

npm npm bundle size License

A Node.js wrapper for Twitch.tv's API.

This package adds a useful abstraction layer to make it easier for developers to interact with the API.

Please note that versions 2.0.0 and later are NOT backwards compatible with earlier versions. There were significant structural overhauls made to this project. Node-ttv is much easier to use now, so depending on how deeply integrated this package is in your project, migrating may not be too difficult.

Getting Started

Register your app

In order to interact with Twitch's API, you must have a registered application with a client ID and secret. You can register a new application here.

Install node-ttv

Create a new project with either npm or yarn. Install the node-ttv package:

npm install node-ttv
or
yarn add node-ttv

Import node-ttv and create a handle to your application

const { Twitch } = require('node-ttv')

const myTwitchApplication = new Twitch(CLIENT_ID, SECRET);

Non-user-specific requests

Requests that do not require user authentication can be made with no further setup required. Endpoints are sorted by resource as specificed by Twitch.tv's API documentation. Refer to their documentation for information on endpoint behavior.

All endpoint functions return a Promise<string> which is a serialized JSON object. Make sure you treat the return value as a Promise<>, using .then() or await.

myTwitchApplication.helix.chat.getGlobalEmotes().then(console.log)

User-specific requests

Making requests on behalf of a user requires their authentication. Node-ttv can generate OAuth 2.0 links to send your users so they can authenticate your app with provided scopes. Read more about how authentication works here.

Your implementation is responsible for handling and storing user access tokens, as well as serving authentication links to users and retrieving access tokens from the redirect.

At this point in time there are no plans to implement support for OIDC tokens. As a result, the Extensions resource is not supported by node-ttv.

Generating authentication links:

const { Twitch, OAuth, Scopes } = require('node-ttv')

const myTwitchApplication = new Twitch(CLIENT_ID, SECRET);

//	Implicit code flow
let sendThisToUser = OAuth.implicitUserAccessToken(CLIENT_ID, REDIRECT_URL, [Scopes.CHANNEL_READ_REDEMPTIONS]);
let orThis = myTwitchApplication.oauth.implicitUserAccessToken(REDIRECT_URL, [Scopes.CHANNEL_READ_REDEMPTIONS]);

//	Authorization code flow
let sendThisToUser = OAuth.authorizationUserAccessToken(CLIENT_ID, REDIRECT_URL, [Scopes.CHANNEL_READ_REDEMPTIONS]);
let orThis = myTwitchApplication.oauth.authorizationUserAccessToken(REDIRECT_URL, [Scopes.CHANNEL_READ_REDEMPTIONS]);

Making authenticated requests:

In this example, USER_ACCESS_TOKEN has been generated with Scopes.CHANNEL_EDIT_COMMERCIAL and '123456789' is their broadcaster_id.

myTwitchApplication.ads.startCommercial(USER_ACCESS_TOKEN, '123456789', 30);

License

Node-ttv is licensed under the MIT permissive license. You may use this package in your projects freely, and no warranty is provided. Read the provided LICENSE file for the complete license text.