var worker = new Worker('worker.js'); worker.addEventListener('message', function(event) { console.log('message received from worker => ', event.data); }); // listen to error event of worker worker.addEventListener('error', function(event) { console.error('error received from worker => ', event); }); worker.postMessage(null); // worker.terminate(); // When worker needs to be terminated from main thread