To create a Node HTTP Client Request with a cookie, we call the http.request method.
For instance, we write
const options = {
hostname: "example.com",
path: "/somePath.php",
method: "GET",
headers: { Cookie: "myCookie=myvalue" },
};
let results = "";
const req = http.request(options, (res) => {
res.on("data", (chunk) => {
results += chunk;
});
res.on("end", () => {});
});
req.on("error", (e) => {});
req.end();
to call http.request with the options object.
In it, we set the Cookie header to the keys and values for the cookie.