Gathering detailed insights and metrics for @atek-cloud/node-fetch-cookies
Gathering detailed insights and metrics for @atek-cloud/node-fetch-cookies
Gathering detailed insights and metrics for @atek-cloud/node-fetch-cookies
Gathering detailed insights and metrics for @atek-cloud/node-fetch-cookies
node-fetch wrapper that adds support for cookie-jars
npm install @atek-cloud/node-fetch-cookies
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
27 Stars
131 Commits
16 Forks
2 Watchers
5 Branches
5 Contributors
Updated on May 01, 2025
Latest Version
2.0.4
Package Id
@atek-cloud/node-fetch-cookies@2.0.4
Unpacked Size
25.65 kB
Size
7.61 kB
File Count
7
NPM Version
7.11.2
Node Version
16.1.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
A node-fetch wrapper with support for cookies.
It supports reading/writing from/to a JSON cookie jar and keeps cookies in memory until you call CookieJar.save()
to reduce disk I/O.
1import {fetch, CookieJar} from "node-fetch-cookies"; 2 3(async () => { 4 // creates a CookieJar instance 5 const cookieJar = new CookieJar("jar.json"); 6 7 // load cookies from the cookie jar 8 await cookieJar.load(); 9 10 // usual fetch usage, except with one or multiple cookie jars as first parameter 11 const response = await fetch(cookieJar, "https://example.com"); 12 13 // save the received cookies to disk 14 await cookieJar.save(); 15})();
1import {fetch, CookieJar} from "node-fetch-cookies"; 2 3(async () => { 4 const cookieJar = new CookieJar(); 5 6 // log in to some api 7 let response = await fetch(cookieJar, "https://example.com/api/login", { 8 method: "POST", 9 body: "credentials" 10 }); 11 12 // do some requests you require login for 13 response = await fetch( 14 cookieJar, 15 "https://example.com/api/admin/drop-all-databases" 16 ); 17 18 // and optionally log out again 19 response = await fetch(cookieJar, "https://example.com/api/logout"); 20})();
This module exports the following classes/functions:
fetch
(default)CookieJar
Cookie
CookieParseError
nodeFetch
Headers
Request
Response
FetchError
isRedirect
: A function that accepts a number, more precisely an http status code as input, and returns, whether the status code is a redirect status code as a boolean.node-fetch
and used by node-fetch-cookies
. It is also exported here, because node-fetch
exports it.cookieJars
A CookieJar instance, an array of CookieJar instances or null, if you don't want to send or store cookies.url
and options
as in https://github.com/node-fetch/node-fetch#fetchurl-optionsReturns a Promise resolving to a Response instance on success.
A class that stores cookies.
flags
The read/write flags as specified below.file
The path of the cookie jar on the disk.cookies
A Map mapping hostnames to maps, which map cookie names to the respective Cookie instance.cookieIgnoreCallback
The callback function passed to new CookieJar()
, that is called whenever a cookie couldn't be parsed.rw
, cookies, cookieIgnoreCallback])file
An optional string containing a relative or absolute path to the file on the disk to use.flags
An optional string specifying whether cookies should be read and/or written from/to the jar when passing it as parameter to fetch. Default: rw
r
: only read from this jarw
: only write to this jarrw
or wr
: read/write from/to this jarcookies
An optional initializer for the cookie jar - either an array of Cookie instances or a single Cookie instance.cookieIgnoreCallback(cookie, reason)
An optional callback function which will be called when a cookie is ignored instead of added to the cookie jar.
cookie
The cookie stringreason
A string containing the reason why the cookie has been ignoredAdds a cookie to the jar.
cookie
A Cookie instance to add to the cookie jar.
Alternatively this can also be a string, for example a serialized cookie received from a website.
In this case fromURL
must be specified.fromURL
The url a cookie has been received from.Returns true
if the cookie has been added successfully. Returns false
otherwise.
If the parser throws a CookieParseError, it will be caught and cookieIgnoreCallback
will be called with the respective cookie string and error message.
Returns an iterator over all domains currently stored cookies for.
Returns an iterator over all cookies currently stored for domain
.
Returns an iterator over all valid (non-expired) cookies.
withSession
: A boolean. Iterator will include session cookies if set to true
.Returns an iterator over all cookies currently stored.
Returns an iterator over all cookies valid for a request to url
.
Removes all expired cookies from the jar.
sessionEnded
: A boolean. Also removes session cookies if set to true
.Reads cookies from file
on the disk and adds the contained cookies.
file
: Path to the file where the cookies should be saved. Default: this.file
, the file that has been passed to the constructor.Saves the cookie jar to file
on the disk. Only non-expired non-session cookies are saved.
file
: Path to the file where the cookies should be saved. Default: this.file
, the file that has been passed to the constructor.An abstract representation of a cookie.
name
The identifier of the cookie.value
The value of the cookie.expiry
A Date object of the cookies expiry date or null
, if the cookie expires with the session.domain
The domain the cookie is valid for.path
The path the cookie is valid for.secure
A boolean value representing the cookie's secure attribute. If set the cookie will only be used for https
requests.subdomains
A boolean value specifying whether the cookie should be used for requests to subdomains of domain
or not.Creates a cookie instance from the string representation of a cookie as send by a webserver.
str
The string representation of a cookie.url
The url the cookie has been received from.Will throw a CookieParseError
if str
couldn't be parsed.
Creates a cookie instance from an already existing object with the same properties.
Serializes the cookie, transforming it to name=value
so it can be used in requests.
Returns whether the cookie has expired or not.
sessionEnded
: A boolean that specifies whether the current session has ended, meaning if set to true
, the function will return true
for session cookies.Returns whether the cookie is valid for a request to url
.
The Error that is thrown when the cookie parser located in the constructor of the Cookie class is unable to parse the input.
new CookieJar(flags, file, cookies)
has been changed to new CookieJar(file, flags = "rw", cookies)
.new CookieJar("rw")
can now be written as new CookieJar()
, new CookieJar("rw", "jar.json")
can now be written as new CookieJar("jar.json")
.rw
is used for flags
in most cases anyways.CookieJar.addFromFile(file)
has been renamed to the async function async CookieJar.load([file = this.file])
, which uses the fsPromises API for non-blocking cookie loading.file
is the file passed to the constructor.CookieJar.save(file)
was moved to async CookieJar.save([file = this.file])
now also uses the fsPromises API.new CookieJar()
now doesn't load cookies from the specified file anymore. To do so, call await CookieJar.load()
after creating the CookieJar.CookieJar.load()
will throw an error if the cookie jar doesn't exist or doesn't contain valid JSON!This project is licensed under the MIT license, see LICENSE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
Found 3/23 approved changesets -- score normalized to 1
Reason
9 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More