https://github.com/rupachowrasia/nodejs-multithreading-worker-threads
A sample app to demonstarte multithreading in node.js using worker-threads
https://github.com/rupachowrasia/nodejs-multithreading-worker-threads
expressjs multithreading nodejs offload-tasks shared-memory threads worker-threads
Last synced: about 1 month ago
JSON representation
A sample app to demonstarte multithreading in node.js using worker-threads
- Host: GitHub
- URL: https://github.com/rupachowrasia/nodejs-multithreading-worker-threads
- Owner: rupachowrasia
- Created: 2025-05-06T01:23:13.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2025-05-06T13:24:01.000Z (about 1 month ago)
- Last Synced: 2025-05-06T14:23:17.111Z (about 1 month ago)
- Topics: expressjs, multithreading, nodejs, offload-tasks, shared-memory, threads, worker-threads
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Multithreading in node.js with Worker Thread
> Node.js is single-threaded by default (everything runs on the main thread), which is great for I/O tasks but bad for heavy computation (e.g., image processing, encryption, parsing large files). To offload heavy computational task we use
Worker Threads in node.js.## π Features
- A Worker Thread is a way to run JavaScript in parallel on multiple threads (useful for CPU-heavy tasks).
- They share memory, but donβt spawn new processes.
- Ideal for CPU-bound tasks (math, compression, etc.) β not I/O-heavy work.
- API:
- Run check: isMainThread
- Send/Receive: parentPort.postMessage(), .on()
- Input data: workerData
- File path: Use new URL('./worker.js', import.meta.url) in ESM## π Tech Stack
- Node.js
- Express
- Node.js worker-thread module## π¦ Installation
```bash
# Clone the repo
git clone https://github.com/rupachowrasia/nodejs-multithreading-worker-threads.git# Move into the project directory
cd nodejs-multithreading-worker-threads# Install dependencies
npm install# Run the app
npm run start