@se-oss/stockfish is a high-performance, TypeScript-first Node.js wrapper for the Stockfish 17.1 WASM chess engine. It provides a convenient API for integrating powerful chess analysis capabilities into your applications, offering functionalities such as position analysis, best move calculation, and direct UCI command interaction.
npm i @se-oss/stockfishInstall using your favorite package manager
pnpm
pnpm install @se-oss/stockfishyarn
yarn add @se-oss/stockfishimport { Stockfish } from '@se-oss/stockfish';
const engine = new Stockfish();
await engine.waitReady();
const analysis = await engine.analyze(
'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1',
15
);
console.log('Best move:', analysis.bestmove); // e2e4
console.log('Score:', analysis.lines[0].score); // { type: 'cp', value: 39 }const engine = new Stockfish();
engine.on('info', (info) => {
console.log(`Depth ${info.depth}: ${info.pv}`);
});
await engine.send('uci');
await engine.send('isready');
await engine.send('position startpos moves e2e4');
await engine.send('go depth 20');import { StockfishPool } from '@se-oss/stockfish';
const pool = new StockfishPool(4); // Create a pool with 4 engine instances
await pool.initialize();
// Acquire an engine, use it, and release it back to the pool
const engine = await pool.acquire();
console.log('Engine acquired');
const analysis = await engine.analyze(
'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1',
10
);
console.log('Best move from pool engine:', analysis.bestmove);
pool.release(engine);
console.log('Engine released');
// Terminate the pool when done
pool.terminate();For detailed API documentation on all methods, please see the API docs.
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.
GPL-3.0 © Shahrad Elahi and contributors.