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

@poppinss/cookie

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@poppinss/cookie

Cookie parser for Node.js

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
decreased by-27.27%
Maintainers
1
Weekly downloads
 
Created
Source

circleci-image npm-image

A generic cookie parser and serializer for Node.js. This module exports handful of functions that can be used with any framework or even raw HTTP server to parse and serialize cookies.

Table of contents

Usage

Install the package from npm as follows:

npm i @poppinss/cookie

# yarn
yarn add @poppinss/cookie

and then use it as follows

import { serialize, CookieOptions } from '@poppinss/cookie'
import { createServer } from 'http'

const expiresAt = new Date()

// Expires in a week
expiresAt.setDate(new Date().getDate() + 7)

const options: CookieOptions = {
  domain: 'foo.com',
  expires: expiresAt,
  httpOnly: true,
  path: '/',
  sameSite: true,
  secure: false,
}

createServer((req, res) => {
  const value = serialize('session-id', '1', null, options)
  res.setHeader('set-cookie', value)
  res.end()
})

Config

Under the hood this package uses cookie module, so make sure to check their docs for the config.

Signing cookies

It is recommended to sign the cookie values using a secret. The signed cookies ensures that they are not tampered on the client side and can be fully trusted.

To sign a cookie, you need to pass a secret as 3rd argument to the serialize method.

import { serialize } from '@poppinss/cookie'
const serialized = serialize('key', 'value', 'a-long-secret-to-sign-cookie')

res.setHeader('set-cookie', serialized)

For reading signed cookies, you will need the same secret, otherwise they will be considered as tampered and removed from the output.

import { parse } from '@poppinss/cookie'
const parsed = parse(req.headers.cookie)

API

Following are the autogenerated files via Typedoc.

Change log

The change log can be found in the CHANGELOG.md file.

Contributing

Everyone is welcome to contribute. Please go through the following guides, before getting started.

  1. Contributing
  2. Code of conduct

Authors & License

Harminder virk and contributors.

MIT License, see the included MIT file.

Keywords

FAQs

Package last updated on 14 May 2019

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