middleware for parsing cookies.

Downloads in past


1001.0.09 years ago9 years agoMinified + gzip package size for in KB

This package provides a very simple cookie parser middleware for your application. This makes it easy to share cookies between and express, for example.


Install the package as an application dependency.
npm install --save


Inject the middleware into your io stack prior to authorization or request handling.
var app = require('express')();
var server = require('http').Server(app);
var io = require('')(server);


function authorization(socket, next) {
  // cookies are available in:
  // 1. socket.request.cookies
  // 2. socket.request.signedCookies (if using a secret)
If you need to use a secret or additional parsing options, this middleware acts as an extremely thin wrapper for express cookie-parser, so pass arguments through exactly as you would when using that. For example, using a secret and custom decoding mechanism could be done with the following:
io.use(cookieParser('keyboard cat', {
  decode: function (str) {
    return str.replace('-', '_');

License is released under the MIT License.