cookie-parser
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
cookie-signature | 1.0.6 | 2.06 kB | MIT | prod | |
cookie | 0.1.3 | 2.77 kB | MIT | prod |
Cookie-Parser is a popular npm package specifically designed to parse HTTP request cookies. It can key the 'Cookie' header and populate req.cookies
with an object thereby making it easier to manage and control web cookies. Furthermore, it has an additional feature enabling signed cookies support by passing a secret
string, which assigns req.secret
so it may be used by other middleware. This optional feature enhances the security by validating the signed cookie values, and the module unsigns and validates any signed cookie values.
To use the Cookie-Parser, first, you need to install it via npm with npm install cookie-parser
. After installing, you can include it in your JavaScript application using the require
function:
var cookieParser = require('cookie-parser')
In your application, initialize and use it like this:
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)
In this example, we've set up a simple Express.js server using cookie-parser as middleware. The cookies of each request can be logged in two categories, Cookies that have not been signed and Cookies that have been signed, through req.cookies
and req.signedCookies
respectively.
The entire documentation for the cookie-parser npm package can be found in the comprehensive README.md file included within the package's GitHub repository. The URL for the repository is git+https://github.com/expressjs/cookie-parser.git. Here you'll find detailed instructions on installing and using the library, as well as its full API reference and example usage snippets. Looking up this URL would give you access to a wealth of information about the cookie-parser package right at your fingertips.