'Is there a way to view any worker_threads that are currently in use in node.js?

I am looking at worker_threads in node and have a simple endpoint that will create a new worker thread and run a CPU intensive script that takes a long time to run.

app.get('/test', (req, res) => {
    const worker = new Worker('./number-test.js');
    worker.on('message', (data) => {
        res.status(200).json({data});
    });
});

I want to set up a second endpoint that will return information about any workers that are currently active. Is there a way that I can see how many workers are currently in use at any one time?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source