title: MEAN stack file upload
body: <p>I am developing a MEAN stack web application and I want to upload file using ng2-file-upload. 
  This is my Angular 2 code. </p>
  
  <p>classroom.component.html</p>
  
  <pre><code>    &lt;input type="file" class="form-control" name="single" ng2FileSelect [uploader]="uploader" /&gt;
      &lt;button type="button" class="btn btn-success btn-s"
                    (click)="uploader.uploadAll()" [disabled]="!uploader.getNotUploadedItems().length"&gt;
              &lt;span class="glyphicon glyphicon-upload"&gt;&lt;/span&gt; Upload all
            &lt;/button&gt;&lt;br /&gt;
  </code></pre>
  
  <p>classroom.component.ts</p>
  
  <pre><code>uploader:FileUploader = new FileUploader({url: "http://localhost:3000/api/material/create-material"});
  </code></pre>
  
  <p>In server.js</p>
  
  <pre><code>app.use(cors());
  app.use('/api',api);
  app.use('/api/material',material);
  </code></pre>
  
  <p>and in material.js</p>
  
  <pre><code>var storage = multer.diskStorage({ //multers disk storage settings
      destination: function (req, file, cb) {
          cb(null, './uploads/');
      },
      filename: function (req, file, cb) {
          var datetimestamp = Date.now();
          cb(null, file.fieldname + '-' + datetimestamp + '.' + file.originalname.split('.')[file.originalname.split('.').length -1]);
      }
  });
  
  var upload = multer({ //multer settings
      storage: storage
  }).single('file');
  
  router.post('/create-material',passport.authenticate('jwt', {session: false}),function (req, res) {
  
      upload(req,res,function(err){
          console.log(req.file);
          if(err){
              res.json({error_code:1,err_desc:err});
              return;
          }
          //res.json({error_code:0,err_desc:null});
      });
  });
  </code></pre>
  
  <p>When uploading a file I get following error </p>
  
  <blockquote>
    <p>XMLHttpRequest cannot load
    <a href="http://localhost:3000/api/material/create-material" rel="noreferrer">http://localhost:3000/api/material/create-material</a>. Response to
    preflight request doesn't pass access control check: The value of the
    'Access-Control-Allow-Origin' header in the response must not be the
    wildcard '*' when the request's credentials mode is 'include'. Origin
    '<a href="http://localhost:4200" rel="noreferrer">http://localhost:4200</a>' is therefore not allowed access. The
    credentials mode of requests initiated by the XMLHttpRequest is
    controlled by the withCredentials attribute.</p>
  </blockquote>
  
  <p>What is the reason for this?</p>