Workify
Worker and Fork process handler with stream pipes works on browser and NodeJS without any modification
To include the lib as standalone in your webpage you can use the cdn or download de files:
<!-- or minified version -->
Browser Usage
Create two files in current work dir with the follow structure.
// worker.js { console;}; ;
<!-- index.html -->
NodeJS Usage
You can also execute the same code in nodejs creating an index.js file
// index.jsvar Worker = Worker worker = 'worker.js'; worker { console; }; ;
And execute to see the result
$ node index.js
Advanced Usage
If you wanna use the same main file in both cases (browser and nodejs), you can put this fallback in the index.js
file
var Worker = { try return workifyWorker catch _ return Worker } worker = 'worker.js'; worker { console; }; ;
Now you can include in html with a script tag
<!-- index.html -->
And get the same result when you execute in node
Browserify
If you need require some modules in your worker, you can do it with browserify, the worker recognize automatically which modules need the worker to work properly