Cookie handling for fetch in Node.js - small CookieJar plugin for Luminara #179950
Replies: 3 comments
-
|
This is a neat plugin for Node.js fetch users! It handles cookies automatically on the server—capturing Set-Cookie headers, injecting Cookie headers on requests, and sharing jars across clients. It keeps behavior consistent across retries and integrates with your Luminara client. If you use fetch server-side and need browser-like cookie handling, this could save a lot of boilerplate. |
Beta Was this translation helpful? Give feedback.
-
|
When using fetch in Node.js (Node 18+/undici), cookies are not handled automatically like they are in the browser. You have to manually read Set-Cookie headers, store them somewhere, and attach the correct Cookie header on every subsequent request. To simplify this workflow, I built luminara-cookie-jar, a plugin for the Luminara HTTP client that integrates a full CookieJar (powered by tough-cookie). The plugin provides: Automatic cookie capture from responses (Set-Cookie) Automatic cookie injection into outgoing requests A shared cookie jar across multiple clients if needed A full CookieJar API via client.jar Compatibility with retries, hedging, timeouts, and stats built into Luminara This allows server-side fetch to behave much closer to a browser environment regarding cookie management. |
Beta Was this translation helpful? Give feedback.
-
|
If you’re using server-side "fetch" and need browser-style cookie handling, this plugin automates the whole process. "luminara-cookie-jar" captures "Set-Cookie" headers, stores them with Tough-Cookie, and injects the correct cookies on every request working seamlessly with Luminara’s retries, hedging, and multi-client setups. It’s a simple way to get full cookie-jar behavior without manual boilerplate. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Body
Hi everyone,
For anyone building on top of
fetchin Node.js or server side environments and struggling with cookies, I released a small plugin that might help.In the browser, cookies are handled for you.
On the server, if you use
fetch(Node 18+ orundici), you need to:Set-CookieheadersCookieheader per requestI built luminara-cookie-jar, a CookieJar plugin for my HTTP client Luminara, to solve this in a clean way using
tough-cookie.Key points:
Set-Cookiecapture on responsesCookieinjection on requestsCookieJarAPI exposed viaclient.jarfor advanced useMinimal example:
Repo: https://github.com/miller-28/luminara-cookie-jar
npm: https://www.npmjs.com/package/luminara-cookie-jar
If you are using
fetchon the server and need browser-like cookie behavior, this might be useful.Guidelines
Beta Was this translation helpful? Give feedback.
All reactions