我正在尝试在基于 express 4 的应用程序中实现文件上传。我遵循本教程:https ://codeforgeek.com/2014/11/file-uploads-using-node-js/
在该代码中:
var express = require('express');
var multer = require('multer');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var users = require('./routes/users');
var app = express();
app.use(multer({
dest: './uploads/',
rename: function (fieldname, filename) {
return filename + Date.now();
},
onFileUploadStart: function (file) {
console.log(file.originalname + ' is starting ...')
},
onFileUploadComplete: function (file) {
console.log(file.fieldname + ' uploaded to ' + file.path)
done = true;
}
}));
行 app.use(multer({
导致错误:
C:\Development\HERA\hera_node\node_modules\express\lib\application.js:206
throw new TypeError('app.use() requires middleware functions');
^
TypeError: app.use() requires middleware functions
at EventEmitter.use (C:\Development\HERA\hera_node\node_modules\express\lib\
application.js:206:11)
at Object.<anonymous> (C:\Development\HERA\hera_node\app.js:17:5)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
可能是什么原因?我在节点和快递方面很新。解释requires middleware functions
并没有告诉我任何事情。