title: Node.js + ajax, uploading a file
body: <p><br><br>
  I've been trying to upload a file with node.js and ajax, yet i can't let it work. I don't get an error, but nothing is in my storage folder.</p>
  
  <p>index.js:</p>
  
  <pre><code>app.post('/newFlavour', function(req, res){
  console.log("[INFO] New flavour request: " + req.body.name);
  
  let form = new formidable.IncomingForm();
  form.uploadDir = path.join(__dirname, '/storage');
  
  form.on('file', function(field, file) {
      fs.rename(file.path, path.join(form.uploadDir, file.name));
  });
  
  form.on('error', function(err) {
      console.log('An error has occured: \n' + err);
  });
  
  form.on('end', function() {
      console.log('success');
  });
  
  form.parse(req); });
  </code></pre>
  
  <p>My function with the ajax request:</p>
  
  <pre><code>function createFlavour() {
  let file = $('#upload-input').get(0).files;
  const formData = new FormData();
  formData.append('uploads', file, file.name);
  
  console.log(file)
  
  $.ajax({
      url: "http://localhost:3000/newFlavour",
      type: "POST",
      dataType: "json",
      data: JSON.stringify({
          name: $('#name').val(),
          file: file
      }),
      contentType: "application/json",
      success: function (data) {
          console.log(data);
      },
      error: function () {
          alert("Error occured");
      },
      complete: function () {
          console.log("complete")
      }
  });
  
  clearModal();  }
  </code></pre>
  
  <p>The input tag:</p>
  
  <pre><code>&lt;input id="upload-input" type="file" name="upload"&gt;&lt;/br&gt;
  </code></pre>
  
  <p>I don't know what i am missing here.</p>
  
  <p>Thanks in advance!</p>