title: Unable to read octet stream response in node js?
body: <p>I have an API that returns response as 'octet-stream'. Here is swagger defination for the same.</p>
  
  <pre><code>responses: {
    '200': {
      description: 'Will return the pdf for an invoice',
        content: {
        'application/octet-stream': {
          schema: '',
        },
      },
    },
  }
  </code></pre>
  
  <p>From postman and swagger ui i am able to save the response as a PDF File. but with node i am not able to write the pdf file. </p>
  
  <p>Below is code for node js to call the API.</p>
  
  <pre class="lang-js prettyprint-override"><code>var fs = require('fs');
  var request = require('request');
  let headers = {
    'Content-Type': 'application/json',
    'accept': "application/octet-stream",
  }
  let body = {
    "invoiceId": "343",
    "slCompId": 243,
    "platfromCompId": "4620816365013235830"
  }
  
  request.post({
    headers,
    url: 'http://localhost:3001/invoice/',
    json: body
  },
    function (error, response, body) {
      console.log(response);
      console.log("response");
      fs.writeFile('a.pdf', response.body, 'binary')
    });
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The PDF file which is written is corrupted. There is nothing inside the file and PDF viewer gives me error in opening the file.</p>