Skip to content

Instantly share code, notes, and snippets.

@Saul-Mirone
Last active February 7, 2017 05:56
Show Gist options
  • Save Saul-Mirone/22d3e095ab8722941c9f7d9c546f34db to your computer and use it in GitHub Desktop.
Save Saul-Mirone/22d3e095ab8722941c9f7d9c546f34db to your computer and use it in GitHub Desktop.
A Node.js cookie module, a middleware based on express or my core.js module
@Saul-Mirone
Copy link
Author

//to use
const Cookie = require('./lib/cookie')
const app = require('./lib/core')()
app.use('/', (req, res, next) => {
  new Cookie(req, res)
  next()
})

app.get('/', (req, res) => {
  req.cookie.set('user', 'mirone')
  res.end()
})

app.get('/update', (req, res) => {
  req.cookie.set('user', 'homura')
  res.writeHead(200, {'Content-Type': 'text/plain'})
  res.end()
})

app.get('/delete', (req, res) => {
  req.cookie.remove('user')
  res.writeHead(200, {'Content-Type': 'text/plain'})
  res.end()
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment