Answer the question
In order to leave comments, you need to log in
Why session in Node.js is quickly reset?
The session is established after authorization. If you switch to links within the site, everything works fine. It is worth leaving the tab inactive, after 5-10 minutes the session is reset.
Session configuration code:
const session = require('express-session');
app.use(session({
secret: 'you secret key',
saveUninitialized: false,
resave: false,
cookie: {
maxAge: 30 * 24 * 60 * 60 * 1000
}
}));
Answer the question
In order to leave comments, you need to log in
secret is passed through an environment variable. Your task is to create an .env file and set the necessary variables there (database connection, secret key, port, host...). To read a file, use dotenv . To do this, create a config folder, for example, in it the index.js file in which you write the exported object with the necessary config. You will use this object to access environment variables in other modules. When including the library, it is better to specify the path to the .env file in full (__dirname ...).
The .env file is not uploaded to the repository, specify it in .gitignore
If you are talking about generating a key as a sequence of characters, then any password generator is an option. More characters and let's go.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question