Answer the question
In order to leave comments, you need to log in
NodeJS. How to work with sessions?
Tell me how to save the session in NodeJs. Below is the content of the server.js file:
const express = require('express');
const app = express();
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
const mongoose = require('mongoose');
const port = process.env.PORT || 8000;
const passport = require('passport');
const flash = require('connect-flash');
const configDB = require('./config/database.js');
mongoose.connect(configDB.url, { useNewUrlParser: true });
require('./config/passport')(passport);
app.configure(function() {
app.use('/views',express.static('views'));
app.use(express.logger('dev'));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.set('view engine', 'ejs');
app.use(express.session({
key: 'FUSTSESSION',
secret:'secret_mega_very_word',
resave: true,
saveUninitialized: true,
cookie: { maxAge: 24 * 60 * 60 * 7 },
store: new MongoStore({
mongooseConnection:mongoose.connection,
ttl : 7 * 24 * 60 * 60
clear_interval:3600 }
)
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
});
require('./app/routes.js')(app, passport);
app.listen(port);
console.log('The magic happens on port ' + port);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question