Use npm to install hamsters.js npm install --save hamsters.js
Import the library into your app.js file like below
<!-- Add Hamsters.js -->
let hamsters = require('hamsters.js');
If you are using Node.js version 10 or higher, you can make use of Node.js's official worker threads implementation by including the Worker object as defined below. Older versions of Node.js should follow the same instructions below and make use of a third party worker implementation if possible. Hamsters.js only officially supports the official Node.js worker implementation, therefore third party implementations are not guaranteed to work out of the box, however you can still implement Hamsters.js into your application stack with plans to upgrade in the future, in this scenario Hamsters.js will make use of the built in legacy mode and computations will be run asynchronously on the main thread.
If you do not include the Worker object the library will make use of the legacy fallback mode allowing you to still write your logic and validate it works with the library but will not provide the performance benefits of multiple threads.
Once you've installed a worker implementation simply pass the Worker object as an argument in the library initialization start options. If you are using Node's native worker implementation, also pass parentPort as a start option.
<!-- Initialize Hamsters.js Node Version 10 and higher -->
hamsters.init({
Worker: Worker,
parentPort: parentPort
});
Next Steps
Once you've downloaded and added the library to your project you should have a variable named hamsters available, this variable is the core of the library. Do not create any globally scoped variables with the same name or you will risk causing compatibility issues. Now that you've successfully added the library to your project, continue reading to begin using the library.