{"id":13758436,"url":"https://github.com/chj-web/node-twitch","last_synced_at":"2025-10-13T01:15:13.886Z","repository":{"id":38848761,"uuid":"174799586","full_name":"chj-web/node-twitch","owner":"chj-web","description":"A wrapper for the Helix Twitch API in NodeJS. Aims to provide methods for all Twitch API endpoints.","archived":false,"fork":false,"pushed_at":"2024-07-30T18:34:39.000Z","size":2151,"stargazers_count":43,"open_issues_count":10,"forks_count":20,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-30T08:11:41.592Z","etag":null,"topics":["nodejs","twitch","twitch-api","typescript","wrapper"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chj-web.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-10T08:57:12.000Z","updated_at":"2025-02-18T09:54:37.000Z","dependencies_parsed_at":"2024-06-29T10:48:47.374Z","dependency_job_id":"33ff8ca5-8df4-427e-9dc0-798996dbf82a","html_url":"https://github.com/chj-web/node-twitch","commit_stats":{"total_commits":280,"total_committers":12,"mean_commits":"23.333333333333332","dds":0.3285714285714286,"last_synced_commit":"3021854b9c44297144496d7a66a0057005484c5c"},"previous_names":["chj-web/node-twitch","plazide/node-twitch"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chj-web%2Fnode-twitch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chj-web%2Fnode-twitch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chj-web%2Fnode-twitch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chj-web%2Fnode-twitch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chj-web","download_url":"https://codeload.github.com/chj-web/node-twitch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253389393,"owners_count":21900751,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","twitch","twitch-api","typescript","wrapper"],"created_at":"2024-08-03T13:00:30.168Z","updated_at":"2025-10-13T01:15:13.812Z","avatar_url":"https://github.com/chj-web.png","language":"TypeScript","funding_links":[],"categories":["Libraries","TypeScript"],"sub_categories":["JavaScript (Node.js)"],"readme":"# node-twitch\nThis package is a wrapper around the Twitch Helix API. It is written in Typescript and provides in-editor documentation for all methods and options. All methods are named after their endpoint names in the [Twitch API Reference](https://dev.twitch.tv/docs/api/reference).\n\n\u003e **NOTE**: This package is still under development. All endpoints are not yet supported. See documentation for all supported endpoints.\n\n## Documentation\nTo see and read about the methods provided by the package, please visit the [documentation](https://plazide.github.io/node-twitch).\n\n## Installation\nThe package is available through NPM, which means you can choose to install it using either `npm` or `yarn`\n\nNPM:\n```sh\nnpm install node-twitch\n```\n\nYarn:\n```sh\nyarn add node-twitch\n```\n\n## Usage\n\nTo start using the package, you need to import and initialize the API class. You need to provide it with your `client_id` and `client_secret` which you get from creating an application on the [Twitch developers site](https://dev.twitch.tv/console). \n\nUsing Typescript or bundler:\n```js\nimport TwitchApi from \"node-twitch\";\n\nconst twitch = new TwitchApi({\n\tclient_id: \"YOUR_CLIENT_ID\",\n\tclient_secret: \"YOUR_CLIENT_SECRET\"\n});\n```\n\nUsing native NodeJS:\n```js\nconst TwitchApi = require(\"node-twitch\").default;\n\nconst twitch = new TwitchApi({\n\tclient_id: \"YOUR_CLIENT_ID\",\n\tclient_secret: \"YOUR_CLIENT_SECRET\"\n});\n```\n\nThis is the easiest way to get started with the package. Using this configuration, an app access token will be automatically fetched for you which will allow to call all public endpoints. \n\n### With an authenticated user\n\nIf you need to access user data, you'll will have to provide an `access_token` which grants access for a user.\n\nTo get this `access_token` you can follow one of the authentication flows on the [Twitch documentation site](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth).\n\n\u003e **NOTE:** It is recommended that you handle the authentication yourself. This package is made for use on the server, and authentication requires you to present a link on the client where users grant your app permissions.\n\n#### Before initialization\n\nIf you want, you can handle all of the authentication yourself and simply pass in an `access_token` when creating a new instance of `TwitchApi`. You should also pass in the scopes the `scopes` that are granted for the passed in `access_token`.\n\n```js\nimport TwitchApi from \"node-twitch\";\n\nconst twitch = new TwitchApi({\n  client_id: \"YOUR_CLIENT_ID\",\n  client_secret: \"YOUR_CLIENT_SECRET\",\n  access_token: \"USER_ACCESS_TOKEN\",\n  scopes: [\"YOUR_SCOPES\"]\n});\n```\n\n#### After initialization\n\nYou can also get user access after creating an instance of `TwitchApi`. There are two important methods to help you with this.\n\n1. **generateAuthUrl**. This method will generate the URL for your users to visit in order to grant permissions to your app. It will use the `client_id`, `client_secret`, and `scopes` passed to the constructor to generate the URL.\n2. **getUserAccess**. This method will fetch the refresh and access tokens using the code returned from Twitch after a user visits the auth URL. This requires you to setup proper callback URLs.\n\nRead more about authentication on the [official Twitch documentation](https://dev.twitch.tv/docs/authentication)\n\n### Examples\nHere are a few examples of common use cases to get you started. The examples assume that you have created an instance of `TwitchApi` called `twitch`. See [usage](#usage) on how to do this.\n\n#### Getting a single stream\n\nTo get the stream information from a single user:\n```js\nasync function getStream(){\n  const streams = await twitch.getStreams({ channel: \"sacriel\" });\n  console.log(streams);\n}\n\ngetStream();\n```\n\nProvided that the stream is live, something like this will be logged:\n```js\n{\n  data: [\n    {\n      id: '39800533772',\n      user_id: '23735582',\n      user_name: 'Sacriel',\n      game_id: '491931',\n      type: 'live',\n      title: 'Cheeky bit of Tarky, maybe PUBG later?',\n      viewer_count: 2013,\n      started_at: '2020-10-28T11:40:49Z',\n      language: 'en',\n      thumbnail_url: 'https://static-cdn.jtvnw.net/previews-ttv/live_user_sacriel-{width}x{height}.jpg',\n      tag_ids: [Array]\n    }\n  ],\n  pagination: {}\n}\n```\n\n#### Getting multiple streams\n\nTo get stream information of multiple channels:\n\n```js\nasync function getStreams(){\n\tconst streams = await twitch.getStreams({ channels: [\"shroud\", \"summit1g\"] });\n\tconsole.log(streams);\n}\n\ngetStreams();\n```\n\nProvided that both streams are live, something like this would be returned:\n\n```js\n{\n  data: [\n    {\n      id: '40860684878',\n      user_id: '26490481',\n      user_name: 'summit1g',\n      game_id: '491931',\n      game_name: 'Escape From Tarkov',\n      type: 'live',\n      title: 'big gains today. [ @summit1g ]',\n      viewer_count: 23923,\n      started_at: '2020-12-07T22:46:40Z',\n      language: 'en',\n      thumbnail_url: 'https://static-cdn.jtvnw.net/previews-ttv/live_user_summit1g-{width}x{height}.jpg',\n      tag_ids: [Array]\n    },\n    {\n      id: '40860769838',\n      user_id: '37402112',\n      user_name: 'shroud',\n      game_id: '65632',\n      game_name: 'DayZ',\n      type: 'live',\n      title: 'Namalsk. | Follow @shroud on socials',\n      viewer_count: 22813,\n      started_at: '2020-12-07T22:53:30Z',\n      language: 'en',\n      thumbnail_url: 'https://static-cdn.jtvnw.net/previews-ttv/live_user_shroud-{width}x{height}.jpg',\n      tag_ids: [Array]\n    }\n  ],\n  pagination: {}\n}\n```\n\n#### Getting thumbnail url from a stream\n\n```js\nasync function getThumbnailUrl(){\n\tconst result = await twitch.getStreams({ channel: \"shroud\" });\n\tconst stream = result.data[0];\n\tconsole.log(stream.getThumbnailUrl());\n}\n\ngetThumbnailUrl();\n```\n\nProvided that the stream is live, this would be returned:\n\n```\nhttps://static-cdn.jtvnw.net/previews-ttv/live_user_shroud-1920x1080.jpg\n```\n\n#### Getting a user's ID\nTo get the ID of a user:\n```js\nasync function getUserId(loginName){\n  const users = await twitch.getUsers(loginName);\n  const user = users.data[0];\n  const userId = user.id;\n\n  console.log(userId);\n}\n\ngetUserId(\"sacriel\");\n```\n\nThis would log:\n```\n23735582\n```\n\n## Problems or issues?\n\nIf you encounter any problems, bugs or other issues with the package, please create an [issue in the GitHub repo](https://github.com/Plazide/node-twitch/issues). \n\n## Get in touch\nIf you have any questions or just want to reach me, you can get in touch with me on Twitter([@chj_web](https://twitter.com/chj_web))","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchj-web%2Fnode-twitch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchj-web%2Fnode-twitch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchj-web%2Fnode-twitch/lists"}