title: Convert PDF file to binary: Node JS and Express
body: <p>I have an application that uploads PDF file and then the file has to be converted into Binary (in the backend without saving the file in a temp folder) to store it in a database.</p>
  <p>I am being able to upload the file and read the data, however, I am not being able to convert it to binary.</p>
  <p>Following is my<code>app.js</code></p>
  <pre><code>var upload = require(&quot;express-fileupload&quot;);
  app.use(upload());
  function upload_file(req, res, next) {
      console.log('here');
      if (!req.files) {
          res.send({
              status: false,
              message: 'No file uploaded'
          });
      }else if (req.method == &quot;POST&quot;) {
          console.log('here');
          var form = new formidable.IncomingForm();
          console.log(form);
          let file = req.files.fileToUpload;
          console.log(file);
          }
      }
  </code></pre>
  <p>The output of the function once a pdf file has been uploaded is:
  <a href="https://i.stack.imgur.com/zvO6p.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zvO6p.jpg" alt="enter image description here" /></a></p>
  <p>I tried <code>const encoded = req.files.fileToUpload.buffer.toString('base64');</code> and I get an error.
  I also tried <code>fs.readFileSync</code> but since I'm not storing the file locally, it throws an error.</p>