cookieSession不是函数

时间:2018-07-17 03:26:17

标签: javascript function express session session-cookies

var express = require('express');
var path = require('path');
var mongo = require('mongodb');
var passport = require('passport');
var mongoose = require('mongoose');
var cookieSession = ('cookie-session');
var passportSetup = require('./config/passport-setup');
var keys = require('./config/keys');

mongoose.connect(keys.mongodb.db, () => {
console.log('Connected to mongodb');
})

var app = express();

//View Engine
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));

app.use(cookieSession({
maxAge: 86400000, //milliseconds
keys: [keys.session.cookieKey]
}));

//init passport
app.use(passport.initialize());
app.use(passport.session());

我正在尝试让cookie会话与我的项目一起工作,但是我遇到了一个问题。终端输出这个。

app.use(cookieSession({
TypeError: cookieSession is not a function

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

您在require前面缺少cookie-session

var cookieSession = ('cookie-session');

应该是

var cookieSession = require('cookie-session');

然后,看起来还不错。