var express =   require("express");
var multer  =   require('multer');
var app         =   express();
var path = require('path');

app.use(express.static(path.join(__dirname, '/')));

var storage =   multer.diskStorage({


  destination: function (req, file, callback) {
    callback(null, './uploads');
  },
  filename: function (req, file, callback) {
    callback(null, 'upload_' + Date.now() + '_' + file.originalname);
  }
});
var upload = multer({ storage : storage}).single('userPhoto');

app.get('/',function(req,res){
      res.sendFile(__dirname + "/index.html");
});

app.post('/uploads',function(req,res){
    upload(req,res,function(err) {
        if(err) {
		console.log("error: ");
		console.log(err);
            return res.end("Error uploading file.");
        }
        res.end("File is uploaded");
    });
});

app.listen(3000,function(){
    console.log("Working on port 3000");
});
