https://github.com/karankraina/nodejs-threads
A very simple function based implementation of node.js worker threads
https://github.com/karankraina/nodejs-threads
clustering nodejs npm threads worker-threads
Last synced: 5 months ago
JSON representation
A very simple function based implementation of node.js worker threads
- Host: GitHub
- URL: https://github.com/karankraina/nodejs-threads
- Owner: karankraina
- License: mit
- Created: 2021-12-26T16:38:24.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-06-01T13:47:28.000Z (about 2 years ago)
- Last Synced: 2025-12-13T03:56:13.685Z (6 months ago)
- Topics: clustering, nodejs, npm, threads, worker-threads
- Language: TypeScript
- Homepage:
- Size: 284 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
Welcome to nodejs-threads 👋
> A very simple function based implementation of node.js worker threads
### 🏠 [Homepage](https://github.com/karankraina/nodejs-threads#readme)
### ✨ [Demo](https://replit.com/@karankraina/nodejs-threads)
## Install
```sh
npm install nodejs-threads
```
## Basic Usage
```javascript
// No need to create a separate file for the worker thread.
const { runInWorker } = require('nodejs-threads');
// OR
import { runInWorker } from 'nodejs-threads';
// Assume this is the CPU intensive task
const { calculateScore } = './users.service';
async function main() {
try {
// Spawn a worker thread like this:
// Does not block the main thread
const result = await runInWorker('./users.service', 'calculateScore', { name: 'Karan' });
console.log('[PRIMARY] : WORKER EXECUTED WITH ...', result);
} catch (error) {
console.log('[PRIMARY] : ERROR', error);
}
}
```
## API Guide
For complete usage guide, refer our [API.md](https://github.com/karankraina/nodejs-threads/blob/main/API.md) file
## Run tests
```sh
npm run test
```
## Author
👤 **Karan Raina **
* Website: https://karanraina.tech/
* Twitter: [@karankraina](https://twitter.com/karankraina)
* Github: [@karankraina](https://github.com/karankraina)
* LinkedIn: [@karankraina](https://linkedin.com/in/karankraina)
## 🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/karankraina/nodejs-threads/issues). You can also take a look at the [contributing guide](https://github.com/karankraina/nodejs-threads/blob/main/CONTRIBUTING.md).
## Show your support
Give a ⭐️ if this project helped you!
## 📝 License
Copyright © 2021 [Karan Raina ](https://github.com/karankraina).
This project is [MIT](https://github.com/karankraina/nodejs-threads/blob/main/LICENSE) licensed.
***
_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_