Questions tagged [node-worker-threads]
108 questions
9
votes
3 answers
Typescript cannot find module 'worker_threads'
I am trying to use node.js 'worker_threads' library with Node v14.15.1 and getting this error
Cannot find module 'worker_threads' or its corresponding type declarations.ts(2307)
tsc
src/api/services/email.service.ts:1:62 - error TS2307: Cannot…

Rohan Gulati
- 384
- 1
- 3
- 9
9
votes
1 answer
How to pass class instances with function through worker_thread.Worker to use function?
To contextualize, I would like to use class instances functions through a Worker Thread from NodeJS "worker_thread" module.
In one main.js file I declare a class and instanciate a new Worker passing the new instance through the workerData…

Helloïs
- 154
- 2
- 9
7
votes
2 answers
Optimizing a file content parser class written in TypeScript
I got a typescript module (used by a VSCode extension) which accepts a directory and parses the content contained within the files. For directories containing large number of files this parsing takes a bit of time therefore would like some advice on…

user9492428
- 603
- 1
- 9
- 25
7
votes
3 answers
Request are not distributed across their worker process
I was just experimenting worker process hence try this:
const http = require("http");
const cluster = require("cluster");
const CPUs = require("os").cpus();
const numCPUs = CPUs.length;
if (cluster.isMaster) {
console.log("This is the master…

falamiw
- 426
- 4
- 16
5
votes
1 answer
How to share context between worker threads
I would like to create a worker thread in a node.js app and pass the current context to the new thread, so I would be able to access my variables and functions within the new thread, Is there is a library to support that? And if not can I a least…

dev3dev
- 128
- 1
- 1
- 9
5
votes
1 answer
Managing multiple long-running tasks concurrently in JS (Node.js)
Golang developer here, trying to learn JS (Node.js).
I'm used to working with goroutines in Go, which for the sake of simplicity let's assume are just threads (actually they're not exactly threads, more like Green Threads, but bear with…

Gilgames
- 481
- 4
- 15
4
votes
1 answer
Why is all of my output appearing before each brute-force attempt when attempting to crack an ethereum keystore wallet file in node.js
I found a post describing how to recover an Ethereum wallet keystore by guessing a single password, however, it uses node synchronous code, and I'm trying to convert it into asynchronous code so that I can use multithreading using…

loud_flash
- 67
- 5
4
votes
0 answers
How to handle Node.js Worker threads in Webpack?
Using Web Workers for the browser is handled by the official worker-loader Webpack module.
Unfortunately worker-loader does not handle Node.js Worker threads.
I'm using Webpack to bundle an AWS Lambda function running on Node.js. And I want to use…

Yves M.
- 29,855
- 23
- 108
- 144
3
votes
0 answers
how to work with response object in nodejs stream, exceljs and worker thread
I am using worker thread and stream at same time in node JS project. At initial I was not able to pass res object through main process to worker thread. I saw many stackoverflow question and solution and wrote a solution which works great. I created…

sabin maharjan
- 61
- 4
3
votes
1 answer
NodeJS Worker Threads and AWS Lambda: Inconsistent Output
I am trying to execute the following AWS lambda:
index.js:
const test = require("test");
exports.handler = async (event) => {
await test.main();
};
test.js:
const {Worker} = require("worker_threads");
const main = () => {
let num1 =…

Vineeth Penugonda
- 63
- 9
3
votes
0 answers
tsconfig paths in worker_threads
I'm spinning up some node workers and need each worker to pull code from a path expressed in tsconfig's paths compiler options. How do you configure worker to acknowledge paths from tsconfig?
here's how I create a Worker:
const workerTs =…

Tom Schreck
- 5,177
- 12
- 68
- 122
3
votes
2 answers
Nodejs Worker threads - How many workers should I spawn in the pool?
I want to use Nodejs Worker threads to handle cpu intensive tasks. I will create a pool of workers available for this.
My question is: How many workers should I spawn in the pool?
Assuming I have a 4 cores, 8 threads cpu - should I spawn a max of 3…

Undead8
- 182
- 1
- 11
3
votes
1 answer
How to listen terminate signal from worker in nodejs?
I have a main process which spawn one new thread using worker_threads. Main process in some particular cases have to close this thread without mattering if it has finished its task or not, so MainThread makes use of terminate() to stop the thread.…

ie8888
- 171
- 1
- 10
3
votes
2 answers
Is it possible to use Node worker threads to perform database inserts?
I recently read about Node's "worker_threads" module that allows parallel execution of Javascript code in multiple threads which is useful for CPU-intensive operations. (NOTE: these are not web workers made by Chrome in the browser)
I'm building a…

Bruce Wang
- 142
- 2
- 10
2
votes
1 answer
Worker threads in express application
I have an express backend application, which listens for http requests from a web application. This backend application is running on AWS ECS Fargate.
So my question is, does it makes sense use multithreading, worker-threads in Node.js, in this…

Ahmet Yazıcı
- 302
- 9