Import
Getting Cookies
Get a Single Cookie
Retrieve a specific cookie value by name:Get All Cookies
Retrieve all cookies as an object:Setting Cookies
Basic Cookie
Set a simple cookie with default options:Cookie with Options
Set a cookie with custom options:Cookie Options
string
default:"/"
The path where the cookie is available
boolean
Whether the cookie should only be sent over HTTPS
string
The domain where the cookie is available
boolean
Whether the cookie is accessible only through HTTP(S)
number
Maximum age in seconds
Date
Expiration date of the cookie
'Strict' | 'Lax' | 'None'
SameSite attribute for CSRF protection
'secure' | 'host'
Cookie prefix for enhanced security
Signed Cookies
Signed cookies provide tamper protection by including a cryptographic signature.Set Signed Cookie
Get Signed Cookie
getSignedCookie returns false if the signature is invalid, undefined if the cookie doesn’t exist, or the cookie value if valid.Get All Signed Cookies
Cookie Prefixes
Cookie prefixes provide additional security guarantees enforced by browsers.Secure Prefix
Cookies with__Secure- prefix must be set with the secure flag:
Host Prefix
Cookies with__Host- prefix must be secure, have path /, and no domain:
Deleting Cookies
Basic Delete
Delete with Options
Match the same options used when setting the cookie:Get Deleted Value
deleteCookie returns the value that was deleted:
Generate Cookie Strings
For advanced use cases, generate cookie strings without setting them:Generate Regular Cookie
Generate Signed Cookie
Multiple Cookies
Set multiple cookies in a single response:Best Practices
Use Signed Cookies
Use signed cookies for sensitive data that needs tamper protection
Set HttpOnly
Use
httpOnly: true for cookies that don’t need JavaScript accessUse Secure Flag
Always use
secure: true in production to ensure HTTPS-only transmissionMatch Delete Options
When deleting cookies, use the same
path and domain used when settingSecurity Considerations
Cookie prefixes (
__Secure- and __Host-) provide additional security enforced by browsers. Use them for sensitive cookies.