All Projects → expressjs → Cookie Parser

expressjs / Cookie Parser

Licence: mit
Parse HTTP request cookies

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Cookie Parser

Cookie Session
Simple cookie-based session middleware
Stars: ✭ 928 (-44.86%)
Mutual labels:  middleware, expressjs, cookie
Body Parser
Node.js body parsing middleware
Stars: ✭ 4,962 (+194.83%)
Mutual labels:  middleware, expressjs
Iris
The fastest HTTP/2 Go Web Framework. AWS Lambda, gRPC, MVC, Unique Router, Websockets, Sessions, Test suite, Dependency Injection and more. A true successor of expressjs and laravel | 谢谢 https://github.com/kataras/iris/issues/1329 |
Stars: ✭ 21,587 (+1182.65%)
Mutual labels:  middleware, expressjs
Method Override
Override HTTP verbs.
Stars: ✭ 548 (-67.44%)
Mutual labels:  middleware, expressjs
Express Status Monitor
🚀 Realtime Monitoring solution for Node.js/Express.js apps, inspired by status.github.com, sponsored by https://dynobase.dev
Stars: ✭ 3,302 (+96.2%)
Mutual labels:  middleware, expressjs
Serve Index
Serve directory listings
Stars: ✭ 360 (-78.61%)
Mutual labels:  middleware, expressjs
Kraken Js
An express-based Node.js web application bootstrapping module.
Stars: ✭ 4,938 (+193.4%)
Mutual labels:  middleware, expressjs
nestjs-cookie-session
Idiomatic Cookie Session Module for NestJS. Built on top of `cookie-session` 😻
Stars: ✭ 35 (-97.92%)
Mutual labels:  cookie, expressjs
Serve Favicon
favicon serving middleware
Stars: ✭ 586 (-65.18%)
Mutual labels:  middleware, expressjs
Session
Simple session middleware for Express
Stars: ✭ 5,571 (+231.02%)
Mutual labels:  middleware, expressjs
Vhost
virtual domain hosting
Stars: ✭ 686 (-59.24%)
Mutual labels:  middleware, expressjs
Secure headers
Manages application of security headers with many safe defaults
Stars: ✭ 2,942 (+74.81%)
Mutual labels:  middleware, cookie
Frontexpress
An Express.js-Style router for the front-end
Stars: ✭ 263 (-84.37%)
Mutual labels:  middleware, expressjs
Express Openapi Validator
🦋 Auto-validates api requests, responses, and securities using ExpressJS and an OpenAPI 3.x specification
Stars: ✭ 436 (-74.09%)
Mutual labels:  middleware, expressjs
deepword
Web editor based on Monaco
Stars: ✭ 25 (-98.51%)
Mutual labels:  middleware, expressjs
Swagger Express Middleware
Swagger 2.0 middlware and mocks for Express.js
Stars: ✭ 543 (-67.74%)
Mutual labels:  middleware, expressjs
Jeff
🍍Jeff provides the simplest way to manage web sessions in Go.
Stars: ✭ 223 (-86.75%)
Mutual labels:  middleware, cookie
node-uploadx
Node.js middleware for handling resumable uploads
Stars: ✭ 17 (-98.99%)
Mutual labels:  middleware, expressjs
Cors
Node.js CORS middleware
Stars: ✭ 5,252 (+212.06%)
Mutual labels:  middleware, expressjs
Serve Static
Serve static files
Stars: ✭ 1,217 (-27.69%)
Mutual labels:  middleware, expressjs

cookie-parser

NPM Version NPM Downloads Build Status Test Coverage

Parse Cookie header and populate req.cookies with an object keyed by the cookie names. Optionally you may enable signed cookie support by passing a secret string, which assigns req.secret so it may be used by other middleware.

Installation

$ npm install cookie-parser

API

var cookieParser = require('cookie-parser')

cookieParser(secret, options)

Create a new cookie parser middleware function using the given secret and options.

  • secret a string or array used for signing cookies. This is optional and if not specified, will not parse signed cookies. If a string is provided, this is used as the secret. If an array is provided, an attempt will be made to unsign the cookie with each secret in order.
  • options an object that is passed to cookie.parse as the second option. See cookie for more information.
    • decode a function to decode the value of the cookie

The middleware will parse the Cookie header on the request and expose the cookie data as the property req.cookies and, if a secret was provided, as the property req.signedCookies. These properties are name value pairs of the cookie name to cookie value.

When secret is provided, this module will unsign and validate any signed cookie values and move those name value pairs from req.cookies into req.signedCookies. A signed cookie is a cookie that has a value prefixed with s:. Signed cookies that fail signature validation will have the value false instead of the tampered value.

In addition, this module supports special "JSON cookies". These are cookie where the value is prefixed with j:. When these values are encountered, the value will be exposed as the result of JSON.parse. If parsing fails, the original value will remain.

cookieParser.JSONCookie(str)

Parse a cookie value as a JSON cookie. This will return the parsed JSON value if it was a JSON cookie, otherwise, it will return the passed value.

cookieParser.JSONCookies(cookies)

Given an object, this will iterate over the keys and call JSONCookie on each value, replacing the original value with the parsed value. This returns the same object that was passed in.

cookieParser.signedCookie(str, secret)

Parse a cookie value as a signed cookie. This will return the parsed unsigned value if it was a signed cookie and the signature was valid. If the value was not signed, the original value is returned. If the value was signed but the signature could not be validated, false is returned.

The secret argument can be an array or string. If a string is provided, this is used as the secret. If an array is provided, an attempt will be made to unsign the cookie with each secret in order.

cookieParser.signedCookies(cookies, secret)

Given an object, this will iterate over the keys and check if any value is a signed cookie. If it is a signed cookie and the signature is valid, the key will be deleted from the object and added to the new object that is returned.

The secret argument can be an array or string. If a string is provided, this is used as the secret. If an array is provided, an attempt will be made to unsign the cookie with each secret in order.

Example

var express = require('express')
var cookieParser = require('cookie-parser')

var app = express()
app.use(cookieParser())

app.get('/', function (req, res) {
  // Cookies that have not been signed
  console.log('Cookies: ', req.cookies)

  // Cookies that have been signed
  console.log('Signed Cookies: ', req.signedCookies)
})

app.listen(8080)

// curl command that sends an HTTP request with two cookies
// curl http://127.0.0.1:8080 --cookie "Cho=Kim;Greet=Hello"

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].