Skip to content
Justice Tech School

Cookies

Read Cookie headers and send Set-Cookie. Use HttpOnly and Secure for session cookies.

Example
const http = require("http");
const s = http.createServer((req, res) => {
  res.setHeader("Set-Cookie", "sid=abc; HttpOnly; Path=/; SameSite=Lax");
  res.end("cookie sent");
}).listen(0, async () => {
  const r = await fetch("http://localhost:" + s.address().port);
  console.log(r.headers.get("set-cookie"));
  s.close();
});

Result

sid=abc; HttpOnly; Path=/; SameSite=Lax

Exercise

Hide from scripts.

Set-Cookie: sid=1; 

Quiz Test

What does HttpOnly do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.