↑ arvau

Stack Overflow / What's the difference between Web Workers and Worker Threads?

I haven't been able to find any resources that explain the difference between Web Workers (https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers), which have been around for years and enable PWA's, and Worker Threads (https://nodejs.org/api/worker_threads.html#worker_threads_worker_threads), which have recently been released in Node.js.

To my understanding both are simply ways of allowing JavaScript to run code in multiple threads. So why are Worker Threads being released as a "new" thing?

Stack Overflow / What's the difference between Web Workers and Worker Threads?

Web Workers are a technology that exists in browsers.

Worker Threads are a technology that exists in node.js.

They have similar goals, but due to environment differences, they have different implementations.

To my understanding both are simply ways of allowing JavaScript to run code in multiple threads.

Yes, that is correct. With significant limitations such as no access to the same variables as the main thread and in the browser, no access to the DOM. Communication between threads and the main thread is generally done via messaging.

So why are Worker Threads being released as a "new" thing?

Node.js has not had the ability to run Javascript code in threads until the "new" Worker Threads. node.js never had Web Workers. Web Workers have existed in the browser for awhile. Before Worker Threads, developers had to use multiple processes to involve additional CPUs or to keep CPU-intensive code from blocking the event loop. Now, node.js developers can do this with Worker Threads.

Some of the developer discussion for why nodejs Worker Threads are different than the browser's Web Workers can be read here: https://github.com/nodejs/node/issues/43583.