express-session和cookie-session的区别


var express = require('express')

  , cookieParser = require('cookie-parser')

  , session = require('cookie-session')

  , express_sess = require('express-session')

  , app = express();

//====================================================

app.use(cookieParser())

// app.use(session({ keys: ['abc'], name: 'user' }));

// {}

// { 'connect.sid': 's:cpI6_ewOlAoRIl0kGkwRVOOZAQnA0n_t.9Q1cv7SP1ADoHArxmqtqQEEXyQE

// fRjaWxsXnQTY4bLI' }

//====================================================

app.use(express_sess({ secret: 'abc', key: 'user'}));

// req.session: { cookie: { 

//      path: '/',

//      _expires: null,

//      originalMaxAge: null,

//      httpOnly: true 

//    } 

// }

// req.cookie: {user: 's:aJ97vKA5CCwxqdTj0AV1siRQ.fWusS5+qfCKICtwkfrzcZ/Gq8P0Qdx/kx8mTBhoOhGU'}

app.get('/', function (req, res, next) {

    res.end(JSON.stringify(req.cookies));

    console.log(req.session)

    console.log(req.cookies)

});

app.listen(3000);

cookie-sessio 和express-session 的区别,和适用场合?

夜千寻
浏览 1608回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Node.js