I need to download a file by POSTing to a REST server.
I was first using http
when it was get
. But now i need to use POST, and node's http post is way too complicated, I dont want to build a low level request, so I dont want to use it.
I am now using request
. https://www.npmjs.com/package/request
Now, my server either sends {isUpdateAvailable:false}
or it sends a tar file.
So i need to save the file, or show 'Already up to date'. How do I pipe to a filestream by checking the response header?
I need to set the pipe along with the request code, so I'm not able to separate the code properly. I need to fs.createWriteStream
only if its necessary. Will it be possible?
So, how do i do it?