Cookie, cookie again. I’ve worked with Cookies a lot, but over a long period of time, and each time I summarize it, I learn more about it. Cookies, which must be placed in the browser, are used by the browser to save some small amount of content. Every time we visit the server, the cookie is attached to the request message and sent to the server. There are no cookies on the server, it just operates on cookies sent by the browser. Because of this, when we process cookies in the server-side code, such as changing the value of a cookie, in fact, the change has not taken effect for the browser, it must be returned to the browser, the change will be really implemented. Of course, on the server side, it’s no different from changing any other variable, such as session. Note: Every time we visit the server, cookies will be attached to the request packet and sent to the server together, but not all cookies will be sent, but cookies under the same top-level domain name of the currently visited website will be sent together. For example, if I have visited Baidu and NetEase in my browser, there are cookies on both sites. When I visit Baidu, the browser just sends baidu cookies; If you visit NetEase, you will only send NetEase cookies. If you want to access NetEase’s cookie when you visit Baidu, it is called cross-domain request and seems to be difficult. In most cases, a child domain accesses a parent domain name or a top-level domain name cookie. For example, baidu.com is a top-level domain name, www.baidu.com, news.baidu.com are secondary domain names, http://guonei.new… Anyway, cookies have a field. The same domain name and the same level of domain name, can be directly operated without specifying the domain, node.js is also the same: \

response.cookie('logFlag'.'out');
Copy the code

But if the cookie is parent, the domain must be specified, otherwise it cannot be changed (but seems to be read directly) : \

response.cookie('logFlag'.'out', {domain:'.baidu.com'});  
Copy the code

The third argument is a JSON parameter that, in addition to specifying the domain name, can also specify the expiration time, path, and so on, if necessary. Now, the browser, you can see this cookie. For example, if I use Chrome to open a website, then press F12, then select the NetWork TAB, and click cookie on the left list, the situation will be clear, very useful. \