Socket
Socket
Sign inDemoInstall

cookie

Package Overview
Dependencies
0
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cookie

cookie parsing and serialization


Version published
Weekly downloads
40M
decreased by-19.36%
Maintainers
1
Install size
6.04 kB
Created
Weekly downloads
 

Package description

What is cookie?

The 'cookie' npm package is a simple, lightweight utility for parsing and serializing cookies in Node.js. It is designed to work with the HTTP server's cookie headers to read and write cookies on the server side.

What are cookie's main functionalities?

Parse Cookie Header

This feature allows you to parse the Cookie header string into an object where each property is a cookie name and its value is the cookie value. It automatically handles URL-encoded cookie values.

const cookie = require('cookie');
const cookies = cookie.parse('foo=bar; equation=E%3Dmc%5E2');

Serialize Cookie

This feature lets you serialize a cookie name-value pair into a Set-Cookie header string with optional attributes such as `HttpOnly`, `Max-Age`, and others. It is useful for setting cookies in HTTP responses.

const cookie = require('cookie');
const serializedCookie = cookie.serialize('foo', 'bar', { httpOnly: true, maxAge: 60 * 60 * 24 });

Other packages similar to cookie

Readme

Source

cookie is a basic cookie parser and serializer. It doesn't make assumptions about how you are going to deal with your cookies. It basically just provides a way to read and write the HTTP cookie headers.

See RFC6265 for details about the http header for cookies.

how?

npm install cookie
var cookie = require('cookie');

var hdr = cookie.serialize('foo', 'bar');
// hdr = 'foo=bar';

var cookies = cookie.parse('foo=bar; cat=meow; dog=ruff');
// cookies = { foo: 'bar', cat: 'meow', dog: 'ruff' };

more

The serialize function takes a third parameter, an object, to set cookie options. See the RFC for valid values.

path

cookie path

expires

absolute expiration date for the cookie (Date object)

maxAge

relative max age of the cookie from when the client receives it (seconds)

domain

domain for the cookie

secure

true or false

httpOnly

true or false

Keywords

FAQs

Last updated on 21 Jun 2012

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc