Home

Awesome

Stockfish.js

<a href="https://github.com/nmrugg/stockfish.js">Stockfish.js</a> is a WASM implementation by Nathan Rugg of the <a href="https://github.com/official-stockfish/Stockfish">Stockfish</a> chess engine, currently used by Chess.com for in-browser engine use.

Stockfish.js is currently updated to Stockfish 16.1.

This edition of Stockfish.js comes in five flavors:

The ASM-JS engine will run in any browser that supports JavaScript. The WASM Stockfish.js 16.1 will run on all modern browsers (Chrome/Edge/Firefox/Opera/Safari) on supported system (Windows 10+/macOS 11+/iOS 16+/Linux/Android), as well as supported versions of Node.js. For slightly older browsers, see the <a href=../../tree/Stockfish16>Stockfish.js 16 branch</a>. For an engine that supports chess variants (like 3-check and Crazyhouse), see the <a href=../../tree/Stockfish11>Stockfish.js 11 branch</a>.

API

In the browser, it is recommended to use the engine via Web Workers. See examples/loadEngine.js for a sample implementation.

You can also run Stockfish.js directly from the command line with Node.js 14.4+. You may need to add some command line flags to get it to run:

node src/stockfish.js

Stockfish.js can be found in the npm repository and installed like this: npm install stockfish.

If you want to use it from the command line, you may want to simply install it globally: npm install -g stockfish. Then you can simply run stockfishjs.

In Node.js, you can either run it directly from the command line (i.e., node src/stockfish.js) or require() it as a module (i.e., var stockfish = require("stockfish");).

Compiling

You need to have the <a href="http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html">emscripten</a> compiler installed and in your path. Then you can compile Stockfish.js with the build script: ./build.js. See ./build.js --help for details. To build all flavors, run ./build.js –all.

Examples

There are examples in the examples folder. You will need to run the examples/server.js server to view the client-side examples. Then you can test out a simple interface at http://localhost:9091/ or a more complete demo at http://localhost:9091/demo.html.

There are also examples of how to use Stockfish.js via Node.js.

Thanks

See <a href="https://raw.githubusercontent.com/nmrugg/stockfish.js/master/AUTHORS">AUTHORS</a> for more credits.

License

(c) 2024, Chess.com, LLC GPLv3 (see <a href="https://raw.githubusercontent.com/nmrugg/stockfish.js/master/Copying.txt">Copying.txt</a>)