So I\'m trying to download a pdf file from a website with my script but the problem is that the file gets broken in the process and I\'m pretty sure it\'s because of wrong e
I know its very late but i seen your question today so i am answering it so that other can get help from this. You can add the encoding when you are trying to write the file i.e-:
fs.writeFileSync("10111.pdf", body,'binary');
As i set encoding format as binary here you can use which is right encoding format according to your requirenment if you are trying to download a pdf that you can set encoding as null.
Hope this would help