在执行快速会话时发生错误
我想在我的应用程序中实现会话。 这是我的代码:
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var swig = require('swig');
var session = require('express-sessions');
var helmet = require('helmet');
var login = require('./routes/login');
var edit_profil = require('./routes/manajemen_profil');
var manajemen_venue = require('./routes/manajemen_venue');
var manajemen_akun = require('./routes/manajemen_list_akun');
var manajemen_event = require('./routes/manajemen_event');
var manajemen_list_email = require('./routes/manajemen_list_email');
var app = express();
// view engine setup
app.engine('html', swig.renderFile);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
//security reason
app.use(helmet());
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', login);
app.use('/edit_profil', edit_profil);
app.use('/manajemen_venue', manajemen_venue);
app.use('/manajemen_list_akun', manajemen_akun);
app.use('/manajemen_event', manajemen_event);
app.use('/manajemen_list_email', manajemen_list_email);
//Session
app.use(session({
secret: 'fffdfee',
resave: false,
saveUninitialized: false,
}));
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('notfound');
});
//test
module.exports = app;
但它返回错误:
C: Users User Desktop manajemen-event-master node_modules express lib application.js:210抛出新的TypeError('app.use()需要中间件函数'); ^
TypeError:app.use()在Object的EventEmitter.use(C: Users User Desktop manajemen-event-master node_modules express lib application.js:210:11)中需要中间件功能。 在Module._compile(module.js:570:32)上的Object.Module._extensions.js(module.js)(C: Users User Desktop manajemen-event-master app.js:45:5) (module.js:446:12)在Function.Module._load(module.js:438:3)上的Module.load(module.js:487:32) .js:497:17)在对象的require(internal / module.js:20:19)。 在Module._compile(module.js:570:32)位于Object.Module._extensions..js(module.js)处(C: Users User Desktop manajemen-event-master bin www:7:11) (module.js:446:12)在Module.runMain(module.js:438:3)处的Function.Module._load(module.js:438:3)处的Module.load(module.js:487:32)的.js:604:10)
你能帮我解决这个问题吗? 谢谢。
您在模块名称中输入了错字。该模块是express-session
,但您的require语句正在加载express-sessions
。