<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          mini-session極簡版session模塊

          聯(lián)合創(chuàng)作 · 2023-09-23 15:24

          mini-session是用于node.js的極簡版session模塊,非持久化。它的數(shù)據(jù)存儲在內(nèi)存里,因此,如果Web服務(wù)器進程重新啟動,session將會丟失。所以,這個模塊主要針對小網(wǎng)站,并沒有太多的數(shù)據(jù)存儲在session中。

          安裝

          在使用 mini-session 之前, 你需要先安裝 Cookies 包。

          npm install cookies

          然后

          npm install mini-session

          Demo

          var http = require("http");
          var Cookies = require("Cookies");
          var Session = require("mini-session");
          
          http.createServer(function(req, res){
              var cookies = new Cookies(req, res);
              var session = new Session(cookies);//init session with cookies
          
              console.log("sessionId = " + session.sessionId);
          
              session.set("userId", 123);
              session.set("userName", "Jhon");
              console.log("after set, session data is :");
              session.dump();
          
              console.log("session.get(\"userId\") = " + session.get("userId"));
          
              session.abandon();
              console.log("after abandon, session data is :");
              session.dump();
          
              res.writeHead(200, {"Content-Type":"text/html"});
              res.end("<h1>session test done!</h1>");
          }).listen(8500);
          
          console.log("Server started : http://localhost:8500");

          控制臺輸出:

          Server started : http://localhost:8500
          
          sessionId = f4e4f42b130bfb4fb663ee67122c02b8
          
          after set, session data is :
          { count: 1,
            f4e4f42b130bfb4fb663ee67122c02b8: { count: 2, userId: 123, userName: 'Jhon' } }
          
          session.get("userId") = 123
          
          after abandon, session data is :
          { count: 0 }
          瀏覽 25
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  五月天婷婷亚洲综合 | 天堂九九 | 中文字幕 国产精品 | 91左爱在线 | 色综合网站 |