title: Error: Can't set headers after they are sent in express-fileupload
body: <pre><code>app.post('/profile', function(req, res) {
      // save file
      if (req.files) {
          let sampleFile = req.files.sampleFile;
          sampleFile.mv('/somewhere/on/your/server/filename.jpg', function(err) {
              if (err)
                  return res.status(500).json(err);
  
          });
      }
      // do some other stuff
      // .............
  
      res.status(200).json(result);
  });
  </code></pre>
  
  <p>I know the problem is caused by <code>return res.status(500).json(err)</code>. I can solve the problem by moving <code>res.status(200).json(result)</code> after <code>if (err)</code> block. Since upload file is optional, the user may posting other data without any uploading files. My question is how to send status 200 with a json result after processed other stuff if the solution is </p>
  
  <pre><code>if (err)
      return res.status(500).json(err);
  res.status(200).json(result);
  </code></pre>