我正在尝试在我的 app.js 文件(使用 node.js/express)中配置 multer,以允许用户上传图像。我在 app.js 中有以下代码:
//various require statements for passport, cookie parser, etc..
var multer = require('multer');
var app = express();
app.use(multer({dest:'./uploads/'}));
当我尝试运行应用程序时,我得到TypeError: app.use() requires middleware functions
我知道这个问题可能需要更多关于我的应用的背景信息,所以如果需要更多信息,请告诉我。
谢谢
编辑:来自 app.js 的更多代码:
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var session = require('express-session');
//var fs = require('fs');
var multer = require('multer');
//Mongo Database
var mongo = require('mongodb');
var monk = require('monk');
var db = monk('localhost:27017/test-api');
//Instagram-API
var api = require('instagram-node').instagram();
//Cookie Manager
var cookieParser = require('cookie-parser');
//Grid
//var Grid = require('gridfs-stream');
//Passport
var passport = require('passport');
var InstagramStrategy = require('passport-instagram').Strategy;
var routes = require('./routes/index');
//var users = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(multer({dest:'./uploads/'}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(methodOverride());
app.use(session({secret: 'keyboard cat', resave: false, saveUninitialized: true }));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, 'public')));
// Make our db accessible to our router
app.use(function(req,res,next){
req.db = db;
next();
});
app.use('/', routes);