title: How to check the file input to know if it's empty in node.js
body: <p>I'm trying to check whether the user has actually chosen a file before pressing on upload or not, if so then check if the file is bigger than 4 MB. If the user has pressed on upload without choosing a file then a message should be sent telling them to go back and choose a file. But this code doesn't seem to work.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="postUpload-wrapper"&gt;
    &lt;form id="uploadpost-form" action="/uploadpost" enctype="multipart/form-data" method="POST"&gt;
      &lt;input type="text" id="postname" placeholder="Title" name="postname"&gt;
      &lt;br&gt;
      &lt;input id="fileupload" type="file" name="image"&gt;
      &lt;br&gt;
      &lt;input type="submit" id "uploadpost-btn" value="Upload" name="uploadpost"&gt;
    &lt;/form&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <pre><code>//UPLOAD A POST
  
  router.post('/uploadpost', upload.single('image'), function(req, res){
  var errors = "";
  
  if(req.body.postname === ""){
      errors += "Write a title";
      res.send(errors);
      return false;
  }
  
  //problem here
  if(req.file.size === 0){
      errors += "You need to choose a file";
      res.send(errors);
      return false;
  }else{
      if(req.file.size &gt; 4000000){
          errors += "Files can only be up to 4 MB in size";
          res.send(errors);
          return false;
      }
  }
  </code></pre>