@awesomeorganization/session-handler

[ESM] The session handler for Node.js according to rfc6265

Usage no npm install needed!

<script type="module">
  import awesomeorganizationSessionHandler from 'https://cdn.skypack.dev/@awesomeorganization/session-handler';
</script>

README

session-handler

:boom: [ESM] The session handler for Node.js according to rfc6265


npm npm npm npm npm npm


Example

Full example in /example folder.

import { http } from '@awesomeorganization/servers'
import { sessionHandler } from '@awesomeorganization/session-handler'

const example = async () => {
  const sessionMiddleware = await sessionHandler()
  http({
    listenOptions: {
      host: '127.0.0.1',
      port: 3000,
    },
    async onRequest(request, response) {
      const { sessionId, storage } = await sessionMiddleware.handle({
        request,
        response,
      })
      const counter = storage.get('counter') ?? 0
      storage.set('counter', counter + 1)
      response.end(`Hi ${sessionId}! you have visited this page ${counter} times`)
    },
  })
  // TRY
  // http://127.0.0.1:3000/
}

example()