I am using session-file-store to maintain the sessions in my Node-Express app.
session-file-store generates a new file for every session. This will create lots of files on the server over time.
Is there any option / way to automatically delete the file after the session expiry?
Here is the part of the code I am using for this -
.
.
const session = require('express-session');
const FileStore = require('session-file-store')(session);
.
.
app.use(session({
genid: (req) => {
return uuid() // use UUIDs for session IDs
},
store: new FileStore(),
secret: MY_SECRET,
resave: false,
saveUninitialized: true,
cookie: { maxAge : SESSION_COOKIE_TIMEOUT }
}));
.
.
Here is the sample file that gets generated by session-file-store -
{"cookie":{"originalMaxAge":59999,"expires":"2019-03-27T03:28:21.597Z","httpOnly":true,"path":"/"},"__lastAccess":1553657241598}
reapInterval
will purge all expired cookies from your server, e.g. to set purging to every 10 secs:
var fileStoreOptions = {
path: "./sessions",
reapInterval: 10,
};```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With