title: File upload to a Node JS server
body: <p>I am trying to upload a file to my node js server using express.
  Here is my nodejs code:</p>
  
  <pre><code>var express=require('express');
  var app=express();
  var fs=require('fs');
  var sys=require('sys');
  app.listen(8080);
  app.get('/',function(req,res){
  fs.readFile('upload.html',function (err, data){
      res.writeHead(200, {'Content-Type': 'text/html','Content-Length':data.length});
      res.write(data);
      res.end();
  });
  
  
  
  });
  app.post('/upload',function(req,res)
  {
  console.log(req.files);
  fs.readFile(req.files.displayImage.path, function (err, data) {
    // ...
    var newPath = __dirname;
    fs.writeFile(newPath, data, function (err) {
      res.redirect("back");
    });
  });
  
  });
  </code></pre>
  
  <p>My upload.html file:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Upload Example&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;form id="uploadForm"
        enctype="multipart/form-data"
        action="/upload"
        method="post"&gt;
    &lt;input type="file" id="userPhotoInput" name="displayImage" /&gt;
    &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  
  &lt;span id="status" /&gt;
  &lt;img id="uploadedImage" /&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I am getting an error that the req.files is undefined.
  What could be wrong? The file upload is also not working.</p>