I have a task that requires a lot of computing without IO while executing and I don\'t want to block thread while executing this task. How can I do this in Node.js
You need background workers and some kind of communication protocol between your web instance and worker instances. For example you can use kue to create tasks queue
// web worker
var kue = require('kue');
var queue = kue.createQueue();
....
app.post('/calculateSomeCrazyStuff', (req, res, err) => {
queue.create('myLongRunningJobName1', {
fibonacciSequence: 52
}).save((err) => {
if (err) {
return next(err);
}
res.status(204).send();
});
});
// jobs worker
var kue = require('kue');
var queue = kue.createQueue();
queue.process('myLongRunningJobName1', function(job, done) {
// calculate fibonacci
done();
});