chess-com is a Node.js module written in TypeScript that allows you to interact with chess.com public APIs and retrieve informations such as:
- Users' general profile info
- Users' ratings and winrates
- All user's matches
- Matches' move sequences and results
- All daily puzzles
Run into your project's terminal:
npm install chess-com
import chess from 'chess-com';
import chess from 'chess-com';
async function run() {
const player = await chess.getPlayer('davipccunha');
if (!player) return;
console.log(player.profile.joined); //1614884411
console.log(player.stats.getStats('rapid').rating); //1202
}
run();
import chess from 'chess-com';
async function run() {
const puzzle = await chess.getDailyPuzzle(true);
if (!puzzle) return;
console.log(puzzle.fen); // 2r5/5Npk/4p2p/8/3P4/3pP2P/5PP1/R5K1 b - - 0 1
console.log(puzzle.solution); // 1...d2 2.Rd1 Rc1 3.Kf1 Rxd1+ 4.Ke2 Rf1 5.Kxd2 Rxf2+
}
run();
import chess from 'chess-com';
import { ArchivesGame } from 'chess-com/src/models/typings/game';
async function run() {
const player = await chess.getPlayer('davipccunha');
if (!player) return;
const archives = await player.games.getArchivedGames();
if (!archives) return;
const frenchGames = archives.filter((game: ArchivesGame) => game.moves.startsWith('1. e4 e6'));
console.log(frenchGames.length); // 361
}
run();
Please let me know of any problems found by filing an issue in GitHub issue. If you have any suggestion or just want to contact me, please send an email to davipccunha@gmail.com
Here is the list of already known problems that I'm working on a fix:
If you are feeling generous and/or would like to support this and other future open-source projects, you can make a donation at my Buy me a coffee page