title: Cannot read property 'file' of null in upload
body: <p>I'm a beginner trying to learn Nodejs and I'm trying upload a file using express.</p>
  
  <p>This is my js file : <code>Express5.js</code></p>
  
  <pre><code>var express = require('express');
  var path = require('path');
  var fs = require('fs');
  var app = express();
  var bodyParser = require('body-parser');
  var data='';
  
  var multer  = require('multer');
  app.use(express.static(path.join(__dirname,'tmp')));
  
  app.use(bodyParser.urlencoded({extended :false}));
  
  app.use(multer({ dest : '/tmp/' }).single('file1')); 
  
  
  app.get('/express_upload.html',function(req,res){
   req.sendFile(__dirname+"/"+"express_upload.html");
  });
  
  app.post('/form_upload',function(req,res){
    console.log("Name : "+req.file.name);
    console.log("Path"+req.file.path);
    console.log("Type"+req.file.type);
    var myfile = __dirname+"/"+req.file.name;
  
    fs.readFile(req.file.path,function(req,resp){
       fs.writeFile(myfile,data,function(err){
          if(err){
              console.log(err);
          }else{
              response = {
                  msg : "File uploaded successfully!",
                  filename : req.file.name
              };
          }
  
          console.log(response);      
          res.end(JSON.stringify(response));
        });
    });
  });
  
  var server=app.listen(8081,function(){
       var host = server.address().address;
       var port = server.address().port;
       console.log("Example app listening at http://%s:%s", host, port)
  
    });
  </code></pre>
  
  <p>This is my html form : <code>express_upload.html</code></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Index&lt;/title&gt;
  &lt;/head&gt;
  &lt;style&gt;
      h2, h3{
          color:Crimson;
          text-align:center;}
  &lt;/style&gt;
  &lt;body bgcolor="MistyRose"&gt;
      &lt;h2 &gt;Welcome&lt;/h2&gt;
      &lt;hr&gt;
      &lt;h3&gt;Node.js &lt;/h3&gt;
      &lt;form action="http://127.0.0.1:8081/form_upload" method="POST" enctype="multipart/form-data"&gt;
          &lt;input type="file" name="file1" size=50&gt;
          &lt;br&gt;
  
          &lt;br&gt;&lt;br&gt;
          &lt;input type="submit" value="UploadFile"&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>Whenever i try to upload a file it gives error Cannot read property 'file' of null.</p>
  
  <p>Error :</p>
  
  <pre><code>C:\Users\nikita\Documents\NodeJspractice&gt;node express5.js
  Example app listening at http://:::8081
  Name : undefined
  Path\tmp\de5a6a92ec86094615cd1690e2821248
  Typeundefined
  C:\Users\nikita\Documents\NodeJspractice\express5.js:33
                                      filename : req.file.name
                                                     ^
  
  TypeError: Cannot read property 'file' of null
  at C:\Users\nikita\Documents\NodeJspractice\express5.js:33:21
  at FSReqWrap.oncomplete (fs.js:135:15)
  </code></pre>
  
  <p>I have tried most of the solutions that I was able to understand still I'm unable to resolve this. Please help if you can find any error or can propose a solution. 
  Thank you </p>