A Little Doubt about nodejs

  node.js, question

Nodejs has such a description about the session in brief.
The book said that hack responded to the writeHead () method in the object and injected the Cookie setting logic into it, as follows:

var writeHead = res.writeHead;
 res.writeead = function(){
 var cookies = res.getHeader('Set-Cookie');
 var session = serialize(key, req.session.id);
 cookies = Array.isArray(cookies) ?   cookies.concat(session):[cookies, session];
 res.setHeader('Set-cookie', cookies);
 return writeHead.apply(this, arguments);

I don’t know two things in it.

1. what does the hack writeHead () method mean?
 2、 session = serialize(key, req.session.id);
 The serilalize () method is not found in JavaScript or nodes, so I don't understand what it means.
 Hope to have friends who know to help solve it

Response. Writehead (Status Code, [Reason Phrase], [Headers]) method, http module inside, Park Ling greatly added the logic of setting cookie to this method here, and Set-Cookie itself is the field of http header.

Serialize () is a simple serialization method to serialize Cookie into standard strings, which are defined on page 183 of the book.