How to get child process to write to an http response in Node?

I have a big job that I fork to a child process. But I want the child process to handle the response instead of the main thread. So the child process generates a big old JSON object, but I don't want it to send it BACK to the main process. I just want it to send the response back itself.

function doWork(req,res) {

     // CALL CHILD PROCESS, And have the child res.json(bigObject)
}
app.get('/dowork', doWork);

I'd like this pass the response ('res'), so that the child writes back to it. Is there a way to do this in Node?

There is no way to do this currently. You used to be able to send file descriptors to child processes a couple of stable branches ago, but that functionality has since been removed. You could also set customFds at spawn time, but that has been deprecated for quite some time now.

Even if you could pass the socket to do the child process, you still would have to recreate the response object somehow.

Your best bet is to have the child send the parent the status code and any headers, set those on the response object in the parent, and then pipe the rest of the output from the child to the response (e.g. child.stdout.pipe(res);).