Biskviit HTTP Cookie Handler
Biskviit is a Node.js module designed for server-side HTTP cookie management. It provides functionality to parse `Set-Cookie` headers from incoming responses, store cookie data in memory, and then generate appropriate `Cookie` headers for outgoing requests based on a specified URL. The current stable version is 2.0.0, which was last updated in August 2017. Due to its age, the package is considered to have an abandoned release cadence. Its key differentiator is its straightforward, in-memory approach to handling cookie state per instance, including basic session timeout management for cookies without explicit expiration dates. It is specifically built for Node.js environments and requires Node.js v6 or higher.
Common errors
-
ReferenceError: require is not defined
cause Attempting to use `require()` in an ECMAScript Module (ESM) context.fixBiskviit is a CommonJS module. Either convert your file to CommonJS (`.js` without `"type": "module"` in `package.json`) or use dynamic `import()`: `const Biskviit = await import('biskviit').then(mod => mod.default);`. -
TypeError: Biskviit is not a constructor
cause Incorrectly importing `Biskviit` or attempting to call it as a function instead of instantiating with `new`.fixEnsure you are using `const Biskviit = require('biskviit');` and then `const biskviit = new Biskviit(options);`. -
Cookies are not being stored or retrieved correctly for a URL.
cause Mismatch between the URL provided to `set` and `get` (e.g., protocol, domain, or path differences) or incorrect `Set-Cookie` string format.fixVerify that the URL used with `get()` exactly matches the context for which the cookies were `set()`, considering domain, path, and secure flags. Ensure `cookieString` passed to `set()` is a valid `Set-Cookie` header value.
Warnings
- breaking The package has not been updated since August 2017, indicating it is largely unmaintained. This poses risks for security vulnerabilities, compatibility issues with newer Node.js versions, and lack of modern features (e.g., native ESM support).
- gotcha Biskviit is a CommonJS-only module and does not provide native ECMAScript Modules (ESM) exports. Attempting to `import` Biskviit in an ESM context will result in a runtime error.
- gotcha The cookie storage is entirely in-memory for each `Biskviit` instance. Cookies are not persisted across application restarts or between different instances of the `Biskviit` class.
- gotcha The package explicitly requires Node.js v6 or newer. Running it on older Node.js versions may lead to unexpected behavior or errors.
Install
-
npm install biskviit -
yarn add biskviit -
pnpm add biskviit
Imports
- Biskviit
import Biskviit from 'biskviit'; import { Biskviit } from 'biskviit';const Biskviit = require('biskviit');
Quickstart
const Biskviit = require('biskviit');
// Create a cookie managing instance with a 5-minute session timeout
const biskviit = new Biskviit({
sessionTimeout: 5 * 60 // expire cookies after 5 minutes
});
// Simulate setting cookies from a 'Set-Cookie' header
biskviit.set('theme=light', 'http://example.com/');
biskviit.set('sessionToken=abc123; Expires=Wed, 09 Jun 2029 10:18:14 GMT; Path=/', 'http://example.com/');
biskviit.set('another=cookie; Max-Age=3600', 'https://secure.example.com/app');
// Get cookies for a specific URL as a string for the 'Cookie' header
const cookiesForExample = biskviit.get('http://example.com/path');
console.log('Cookies for example.com:', cookiesForExample); // Expected: theme=light; sessionToken=abc123
const cookiesForSecureExample = biskviit.get('https://secure.example.com/app/dashboard');
console.log('Cookies for secure.example.com:', cookiesForSecureExample); // Expected: another=cookie
// List all available cookies for a URL as objects
const cookieObjects = biskviit.list('http://example.com/');
console.log('Cookie objects for example.com:', cookieObjects);