node.js - stream file without saving it temporarily

Problem

So this is my setup

I have a client from which files are uploaded to the node.js server (serverA) and from there I want to stream the files to another server (serverB) without saving the file temporarily (on serverA).

What is the simplest and the best way to achieve this?

I am able to upload the file to serverA but I don't want the temporary file to be stored.

Update:

its a simple ajax file uplaod to (severA)... The idea is to transfer byte-wise so that even if the connection goes off, you can read it back from that particular byte.

I am using express.js on serverA and backbone.js is the client using which I do the ajax uploads. For now there's no connection between A and B as such, they communicate through endpoints. serverA is running on port 4000 and serverB on port 5000. I want to somehow pipe the file from serverA to an endpoint on serverB.

Problem courtesy of: Madhusudhan

Solution

Since HttpRequest is a stream, you could use the request module to pipe the current request into the other endpoint inside your express route:

app.post('myroute', function (req, res) {
    var request = require('request');
    req.pipe(request.post('/my/path:5000')).pipe(res);
});

Would that approach work?

Solution courtesy of: SonOfNun

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.