
Product
Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.
Working with cookies shouldn't be complicated or scary. fami makes HTTP cookie management simple, safe, and of course type-safe.
fami is a lightweight library focused on correctness and developer experience, following modern RFC 6265bis standards with an intuitive API designed for today's web.
If you're already using a cookie library, you might wonder why you should switch. Here's what sets fami apart:
vs. cookie (the most popular choice)
Note:
cookieis a perfectly valid choice and is very well maintained. It has been around for a long time and is a well-established library with battle-tested code and a large community.
vs. rolling your own
Perfect for:
fami is runtime-agnostic and works in all of your favorite runtimes. Such as but not limited to: Bun, Node.js, Deno, Cloudflare Workers, Vercel, Netlify, and more.
bun add fami
# or
npm install fami
# or
yarn add fami
# or
pnpm add fami
The High-level API provides a simple and intuitive abstraction for managing your cookie attributes and names. Define your cookie names once and use them throughout your application with full type safety. Set sane defaults for your cookies and serialize/parse them worry free of edge cases.
import { Fami } from "fami";
const fami = new Fami({
theme: {},
session: {
httpOnly: true,
secure: true,
maxAge: 3600,
},
});
const cookies = fami.parse("theme=light; session=value");
console.log(cookies);
// { theme: "light", session: "value" }
const theme = fami.serialize("theme", "light");
console.log(theme);
// "theme=light"
// You can also override the default attributes with your own
const session = fami.serialize("session", "value", {
maxAge: 7200,
});
console.log(session);
// "session=value; Max-Age=7200; Secure; HttpOnly"
const deleteSession = fami.delete("session");
console.log(deleteSession);
// "session=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT"
If a cookie definition includes secret, related operations become asynchronous across fami and all adapters.
For secret cookies:
fami.serialize(...) and fami.delete(...) return Promise<string>fami.parse(...).cookieName returns Promise<string | undefined>ctx.setCookie(...), ctx.deleteCookie(...), res.setCookie(...), and res.deleteCookie(...) should be awaited before response is sentUseful when you want more control or are moving away from other libraries. You can easily check if Fami is compatible with your existing code. If it is, you should migrate over to the High-level API.
import { parse } from "fami";
const cookies = parse("foo=bar; baz=qux");
console.log(cookies);
// { foo: "bar", baz: "qux" }
import { serialize } from "fami";
const cookie = serialize("session", "value", {
httpOnly: true,
secure: true,
maxAge: 3600,
});
console.log(cookie);
// "session=value; Max-Age=3600; Secure; HttpOnly"
Kaito is a modern, type-safe functional HTTP framework.
fami provides first‑class Kaito support through a tiny utility that extends the Kaito context with fami's methods. The utility adds functions like ctx.setCookie("session", "value") and ctx.deleteCookie("session") to the Kaito context which make it a great experience to work with.
import { create } from "@kaito-http/core";
import { fami } from "fami/kaito";
const kaito = create().pipe(
fami({
session: {},
}),
});
const app = kaito.get("/", ({ ctx }) => {
const session = ctx.cookies.session;
if (session) {
return {
message: "You are logged in!",
};
}
throw new KaitoError(401, "Unauthorized");
});
Bun.serve({
fetch: app.serve(),
});
For more details, you can take a look at the examples.
Express is the most popular web framework for Node.js.
fami provides a dedicated Express adapter through fami/express that gives you type-safe cookie management with full Express autocomplete. The adapter provides a middleware that augments req and res with fami's methods, and a handler() wrapper that narrows the types so req.cookies, res.setCookie(), res.deleteCookie() and res.json() all have full autocomplete and type safety.
[!IMPORTANT] You MUST install the
@types/expresspackage manually, for the best experience.
import express from "express";
import { fami } from "fami/express";
const app = express();
const f = fami({ session: {} });
app.use(f.middleware());
app.get(
"/",
f.handler((req, res) => {
const session = req.cookies.session; // typed as string | undefined
res.setCookie("session", "value"); // autocomplete for cookie names
res.json({ session }); // full Express autocomplete
}),
);
app.listen(3000);
For more details, you can take a look at the examples.
fami targets the latest HTTP State Management draft (RFC 6265bis, draft‑21 as of 2025), and future drafts onwards.
Highlights:
Partitioned (CHIPS), Priority, and SameSite configuration.fami was inspired by the following libraries:
Although fami is runtime-agnostic, it is developed and tested using Bun. It is advised to use Bun when developing.
# install deps
bun install
# dry run the publish command to see what would be published,
# this also runs the test suite and builds the package
bun run publish --dry-run
bun t
The above command is a shortcut for bun run test that executes the test suite and generates a coverage report via Bun's built-in coverage tool.
The test suite covers:
Releases are published automatically via GitHub Actions. Existing versions on npm are never overwritten and each release is immutable, and new versions are always published with a new semver tag.
MIT License, see LICENSE for details.
FAQs
Working with cookies shouldn't be complicated or scary.
The npm package fami receives a total of 55 weekly downloads. As such, fami popularity was classified as not popular.
We found that fami demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.

Research
More than 140 Mastra npm packages were compromised in a supply chain attack that used a typosquatted dependency to deliver a cross-platform infostealer during installation.

Research
/Security News
A new npm package tests AI malware scanners with prompt injection, safety-triggering comments, context flooding, and obfuscated JavaScript.