Skip to content

Instantly share code, notes, and snippets.

@evangow
Created October 30, 2017 02:11
Show Gist options
  • Save evangow/89de84daf79481dab6a7ffc1e8272e41 to your computer and use it in GitHub Desktop.
Save evangow/89de84daf79481dab6a7ffc1e8272e41 to your computer and use it in GitHub Desktop.
//npm modules
const express = require('express');
const uuid = require('uuid/v4')
const session = require('express-session')
const FileStore = require('session-file-store')(session);

// create the server
const app = express();

// add & configure middleware
app.use(session({
  genid: (req) => {
    console.log('Inside the session middleware')
    console.log(req.sessionID)
    return uuid() // use UUIDs for session IDs
  },
  store: new FileStore(),
  secret: 'keyboard cat',
  resave: false,
  saveUninitialized: true
}))

// create the homepage route at '/'
app.get('/', (req, res) => {
  console.log('Inside the homepage callback function')
  console.log(req.sessionID)
  res.send(`You hit home page!\n`)
})

// tell the server what port to listen on
app.listen(3000, () => {
  console.log('Listening on localhost:3000')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment