Not understanding Cookies in Node.js
<p>I am making a program in Node.js that involves cookies. I don't want to use a library like express. I found the following code online for using cookies, but I am not exactly sure how it works. Could somebody break it down for me? Also, I am not sure which part of the code reads cookies in the system and which part writes them. Could you clarify that as well?</p>

<p>Thank you:</p>

<p>Here is the code:</p>

<pre><code>var http = require('http');

function parseCookies(cookie) {
    return cookie.split(';').reduce(
        function(prev, curr) {
            var m = / *([^=]+)=(.*)/.exec(curr);
            var key = m[1];
            var value = decodeURIComponent(m[2]);
            prev[key] = value;
            return prev;
        },
        { }
    );
}

function stringifyCookies(cookies) {
    var list = [ ];
    for (var key in cookies) {
        list.push(key + '=' + encodeURIComponent(cookies[key]));
    }
    return list.join('; ');
}

http.createServer(function (request, response) {
  var cookies = parseCookies(request.headers.cookie);
  console.log('Input cookies: ', cookies);
  cookies.search = 'google';
  if (cookies.counter)
    cookies.counter++;
  else
    cookies.counter = 1;
  console.log('Output cookies: ', cookies);
  response.writeHead(200, {
    'Set-Cookie': stringifyCookies(cookies),
    'Content-Type': 'text/plain'
  });
  response.end('Hello World\n');
}).listen(1234);
</code></pre>