title: Consume content of the file without saving the file with express.js?
body: <p>I am writing an application where I have an CVS file upload. I have an CVS parser so from my frontend I can upload the CSV to backend, process it and save it to database. After that I am deleting the file. </p>
  
  <p>I am using multer to accept the file and it get's saved to hard drive, then I can read the file and consume the content of the file and delete the file. All fine and all good there.</p>
  
  <p>I am trying to figure out if there is a way to skip actually saving the file altogether. Is there an easy way of just submitting the file from <code>'multipart/form-data'</code> form and reading the content directly with express without having to save it on file system?</p>
  
  <p>Just for reference, this is what I have now and it is working as expected</p>
  
  <p>On frontend: </p>
  
  <pre><code>static fileUpload(file) {
    const url = '/api/statement-upload';
    const formData = new FormData();
    formData.append('file', file);
    const config = {
      headers: {
        'content-type': 'multipart/form-data'
      }
    };
    return post(url, formData, config);
  }
  </code></pre>
  
  <p>On my express server I'm using multer and have defined route like this:</p>
  
  <pre><code>import multer from 'multer';
  
  export default function (router) {
    const upload = multer({dest: 'uploads/'});
  
    router.use('/api/statement-upload', upload.single('file'), (req, res) =&gt; {
      cvsParser(req.file.path)
        .then(() =&gt; res.json({error: false}))
        .catch(e =&gt; res.json({error: e}));
    });
  
    return router;
  };
  </code></pre>
  
  <p>And in my cvsParser then I have this:</p>
  
  <pre><code>export default function (filePath) {
    let content = fs.readFileSync(filePath, 'binary');  
    fs.unlink(filePath, () =&gt; {});
  
    // do nasty stuff to content and save it gently in the database
  }
  </code></pre>
  
  <p>So in short again, is there a way to do this without having to resort to saving the CSV to file system before I can consume the content of the file? </p>
  
  <p>Is this even possible considering the file encodings, etc, maybe there is no way around using <code>fs</code>?</p>