npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@molecule/api-middleware-cookie-parser

v1.0.1

Published

Cookie parser middleware interface for molecule.dev

Readme

@molecule/api-middleware-cookie-parser

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Cookie parser middleware for molecule.dev.

Core interface — the actual implementation is provided via bonds. Install a cookie parser bond (e.g., @molecule/api-middleware-cookie-parser-express) to provide cookie parsing.

Quick Start

import express from 'express'
import { cookieParser, createCookieParserMiddleware } from '@molecule/api-middleware-cookie-parser'

const app = express()

// Default parser (unsigned cookies) — requires the bond to be wired,
// e.g. @molecule/api-middleware-cookie-parser-express.
app.use(cookieParser)

// Signed cookies: pass the server-side secret; verified values land on
// req.signedCookies with the Express bond.
const sessionSecret = process.env.SESSION_SECRET ?? ''
app.use(createCookieParserMiddleware(sessionSecret))

Type

middleware

Installation

npm install @molecule/api-middleware-cookie-parser @molecule/api-bond

API

Interfaces

CookieParseOptions

Options for cookie parsing.

interface CookieParseOptions {
  decode?: (value: string) => string
}

Types

CookieParserFactory

Factory function type for creating cookie parser middleware with secret and options.

type CookieParserFactory = (secret?: string | string[], options?: CookieParseOptions) => Middleware

Middleware

Generic middleware type — framework-agnostic.

type Middleware = (req: unknown, res: unknown, next: (err?: unknown) => void) => void

Functions

cookieParser(req, res, next)

Default cookie parser middleware that delegates to the bonded implementation. Parses the Cookie header and populates req.cookies.

function cookieParser(req: unknown, res: unknown, next: (err?: unknown) => void): void
  • req — The incoming request object.
  • res — The response object.
  • next — The next middleware function.

Returns: The result of the bonded cookie parser invocation.

createCookieParserMiddleware(secret, options)

Creates cookie parser middleware with custom options via the bonded factory.

function createCookieParserMiddleware(
  secret?: string | string[],
  options?: CookieParseOptions,
): Middleware
  • secret — Secret string(s) for signed cookie verification.
  • options — Cookie parsing options (e.g., custom decode function).

Returns: A middleware function that parses cookies.

getCookieParser()

Gets the bonded cookie parser middleware.

function getCookieParser(): Middleware

Returns: The bonded cookie parser middleware function.

getCookieParserFactory()

Gets the bonded cookie parser factory.

function getCookieParserFactory(): CookieParserFactory | null

Returns: The factory function, or null if none has been bonded.

hasCookieParser()

Checks if a cookie parser middleware has been bonded.

function hasCookieParser(): boolean

Returns: true if a cookie parser is available.

setCookieParser(parser)

Bonds a cookie parser middleware implementation for use by getCookieParser() and cookieParser.

function setCookieParser(parser: Middleware): void
  • parser — The middleware function that parses cookies.

setCookieParserFactory(factory)

Bonds a cookie parser factory for creating parsers with custom secrets and options.

function setCookieParserFactory(factory: CookieParserFactory): void
  • factory — A function that creates cookie parser middleware from options.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/api-bond ^1.0.1

Runtime Dependencies

  • @molecule/api-bond

This parses INCOMING cookies onto req.cookies. When your app SETS an auth/session cookie, the flags are what matter:

  • Auth/session cookies MUST be httpOnly + secure + sameSite. httpOnly stops JS (and therefore XSS) from reading the token; secure restricts it to HTTPS in production; sameSite: 'lax'|'strict' blocks CSRF. A readable session cookie is stealable.
  • Never store a secret or raw token in a plain, non-httpOnly cookie — it's readable by the client and sent on every request. Sign cookies with a SERVER-side secret (SESSION_SECRET) when you need tamper detection, and keep the real state server-side keyed by the session.