View on NPM
Node.js Package for Twitch Chat
Connect to and interact with Twitch chat from Node.js with this simple package.
View on NPM

Getting started

Install

Install using npm:

				npm i tmi.js
			

Anonymous connection

				
const tmi = require('tmi.js');

const client = new tmi.Client({
	connection: {
		secure: true,
		reconnect: true
	},
	channels: [ 'my-name' ]
});

client.connect();

client.on('message', (channel, tags, message, self) => {
	// "Alca: Hello, World!"
	console.log(`${tags['display-name']}: ${message}`);
});
				
			

OAuth token authorization

				
const tmi = require('tmi.js');

const client = new tmi.Client({
	options: { debug: true },
	connection: {
		secure: true,
		reconnect: true
	},
	identity: {
		username: 'my-bot-name',
		password: 'oauth:my-bot-token'
	},
	channels: [ 'my-name' ]
});

client.connect();

client.on('message', (channel, tags, message, self) => {
	// Ignore echoed messages.
	if(self) return;

	if(message.toLowerCase() === '!hello') {
		// "@alca, heya!"
		client.say(channel, `@${tags.username}, heya!`);
	}
});