Getting started with Node.js
Requirements
Node.js 18 or later. The WebAssembly build needs Node.js 20.19, 22.13, 23.5, or later.
Install a package
Install the package of each format family that you use. The examples on this page use the image family.
Detect the format of a file
Give the bytes of a file to detect. The function needs only the first bytes of
the file. 64 bytes are enough for most image files.
When the format is not recognized, detect returns null. detect returns a
promise and does the work on the libuv thread pool. detectSync is the
synchronous form.
List the supported formats
supportedFormats returns the identifier of each format that detect can
return.
Compare two images
compareImages decodes two PNG files, compares them with the algorithm of
pixelmatch, and encodes the diff image.
Next steps
- Read the API reference of each format family.
- If no native addon can load in your environment, read WebAssembly build.
- If you use pngjs and pixelmatch, read Migrate from pngjs and pixelmatch.
- If you use ssim.js, read Migrate from ssim.js.
- Read Development to build anyformat from source.