1

Currently my usecase is my node.js Server Server A needs to create a CSV file then send that CSV to another Server Server B which only accepts application/octet-stream.

Currently I'm manually CURLing the csv to upload it to Server B.

curl -H "Content-Type:application/octet-stream" 
    -X PUT https://someexample.com/url/what/not 
    --upload-file newlyCreated.csv

But I need to automate the curl above and wanted to use node.js since Server A is built in node.js. My instincts leads me to use streams but I can't seem to make it work.

fs.createReadStream('/path/to/csv').pipe(httpRequestToServerB)

Then respond to client and send a JSON that it is successful

ponury-kostek
  • 7,824
  • 4
  • 23
  • 31
bumblebeen
  • 642
  • 8
  • 21

1 Answers1

1

Currently, I've found the answer to my question using request NPM module:

fs.createReadStream('/path/to/csv').pipe(request.post('url').on('end', (done) => {
  console.log('Upload Done')
}));

Hope this helps

Anas Tiour
  • 1,344
  • 3
  • 17
  • 33
bumblebeen
  • 642
  • 8
  • 21