Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cookie-parser

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cookie-parser

cookie parsing with signatures

  • 1.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.7M
decreased by-7.1%
Maintainers
2
Weekly downloads
 
Created

What is cookie-parser?

The cookie-parser npm package is a middleware which parses cookies attached to the client request object. It can parse signed cookies with a secret and populate req.cookies with an object keyed by cookie names. It's commonly used in Express and Connect applications.

What are cookie-parser's main functionalities?

Parse Cookies

This code sets up an Express server that uses cookie-parser to parse cookies from the request. It logs the cookies to the console on a GET request to the root path.

const express = require('express');
const cookieParser = require('cookie-parser');

const app = express();
app.use(cookieParser());

app.get('/', (req, res) => {
  console.log('Cookies: ', req.cookies);
  res.send('Check the console for cookies');
});

app.listen(3000);

Parse Signed Cookies

This code demonstrates how to use cookie-parser to parse signed cookies. The secret provided to cookieParser() is used to validate the signed cookies, which are then available in req.signedCookies.

const express = require('express');
const cookieParser = require('cookie-parser');

const app = express();
app.use(cookieParser('yourSecret')); // Replace 'yourSecret' with your actual secret string

app.get('/', (req, res) => {
  console.log('Signed Cookies: ', req.signedCookies);
  res.send('Check the console for signed cookies');
});

app.listen(3000);

Other packages similar to cookie-parser

Keywords

FAQs

Package last updated on 11 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc