var multer = require('multer'),
storage = multer.diskStorage({
destination: function(req, file, callback) {
callback(null, __dirname + '/public/tmp/upload_avatars');
},
filename: function(req, file, callback) {
var filename = file.fieldname + '-' + Date.now() + '-' + file.originalname;
cb(null, filename);
}
}),
upload = multer({ storage: storage });
req.files[0].filename
var express = require('express'),
http = require('http'),
fs = require('fs');
var app = express();
// Задаем пути поиска css и img файлов
app.use(express.static(__dirname + '/css'));
app.use(express.static(__dirname + '/img'));
// Создаем сервер
http.createServer(app).listen(3000, function(){
console.log("Server started");
});
// При входе на главную страницу выдаем index.html
app.get('/', function(req, res, next){
fs.readFile('./index.html', function(err, info){
if (err) throw err;
res.end(info);
})
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<h1>Hello</h1>
<img src="nodejs.png" alt="logo">
</body>
</html>
body {
background: #ddd;
}
block = document.getElementById("block");
animate = function(options) {
var measure, start;
start = performance.now();
return requestAnimationFrame(measure = function(time) {
var progress, timeFraction;
timeFraction = (time - start) / options.duration;
progress = options.timing(timeFraction);
if (progress < 0) {
progress = 0;
}
if (progress > 1) {
progress = 1;
}
options.draw(progress);
if (timeFraction < 1) {
return requestAnimationFrame(measure);
}
});
};
block.style.left = "0";
block.style.top = "0";
document.onmousemove = function(e) {
var dX, dY, lastX, lastY, theX, theY;
lastX = parseInt(block.style.left);
theX = e.pageX;
dX = theX / 5 - lastX + 500;
lastY = parseInt(block.style.top);
theY = e.pageY;
dY = theY / 5 - lastY + 200;
return animate({
duration: 100,
timing: function(timeFraction) {
return timeFraction;
},
draw: function(progress) {
block.style.left = (lastX + progress * dX) + "px";
return block.style.top = (lastY + progress * dY) + "px";
}
});
};
dX = 500 - theX / 5 - lastX
dY = 200 - theY / 5 - lastY