Run long running express API process in seperate thread NodeJs
<p>I have an API call that takes about 5-10 minutes to process. I set a timeout method around it so that I get an immediate API response with a status of queued.</p>

<p>Simple visual below</p>

<pre><code>doWork(object) =&gt; { /*... Takes 5 minutes */ }

app.post('/longProcess',(req,res)=&gt; {
    setTimeout(this.doWork(req.body), 1000);
    res.send({ status: 'queued' });
})
</code></pre>

<p>This works for the first request giving an immediate response. But the second request is locked waiting for doWork to finish.</p>

<p>Instead of a using SetTimeout what I'd really like to do is send the longProcess to a separate single-thread that queues and processes theses one by one.</p>

<p>Any suggestions?</p>