express session destroy

const express = require('express');
const session = require('express-session');

const app = express();

// Set up session middleware with a secret key
app.use(session({
  secret: 'your-secret-key',
  resave: false,
  saveUninitialized: true
}));

// Route to destroy a session
app.get('/logout', (req, res) => {
  // Destroy the session
  req.session.destroy((err) => {
    if (err) {
      return res.status(500).send('Error while logging out');
    }
    // Redirect to the home page after successfully destroying the session
    res.redirect('/');
  });
});

// Start the Express server
const port = 3000;
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});