Vietnam

    Nodejs.vn

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Groups
    • Search

    Xin 1 bài hướng dẫn về sử dụng SESSION trong NODE

    Node.JS
    3
    5
    6213
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • haidangdevhaui
      haidangdevhaui last edited by haidangdevhaui

      Như title,Mình là 1 Noder mới vào nghề.MÌnh đang nghiên cứu về MEAN Stack.Vậy mình xin các noder cho mình 1 bài hướng dẫn về việc sử dụng SESSION trong việc lưu trữ phiên làm việc để mình có thể tiếp tục khám phá Node.Xin cảm ơn 😃

      tobi

      1 Reply Last reply Reply Quote 0
      • K
        katanhich Sailor last edited by

        google co day ma ban

        1 Reply Last reply Reply Quote 0
        • J
          jokyspy last edited by

          Nếu dùng MEAN stack bạn có thể tham khảo bộ http://meanjs.org/ cung cấp code ban đầu để khởi tạo 1 server, rất thuận tiện cho việc học.

          Để sử dụng session, khi khai báo các middleware (trong meanjs thì tại /config/express.js) bạn sẽ thấy các đoạn code:

          var session = require('express-session')
          var cookieParser = require('cookie-parser')
          var mongoStore = require('connect-mongo')({
          	session: session
          })
          
          // CookieParser should be above session
          app.use(cookieParser())
          
          // Express MongoDB session storage
          app.use(session({
          	saveUninitialized: true,
          	resave: true,
          	secret: config.sessionSecret,
          	cookie: {maxAge: 2592000000}, // equivalent to 1 month
          	store: new mongoStore({
          		db: db.connection.db,
          		collection: config.sessionCollection
          	})
          }))
          

          3 module cookie-parser express-session và mongo-connect là 3 module bạn có thể tìm hiểu thêm về vấn đề này.

          haidangdevhaui manhhip94 2 Replies Last reply Reply Quote 0
          • haidangdevhaui
            haidangdevhaui @jokyspy last edited by

            Thanks bác .tại e thấy cái passport nó phức tạp quá nên muốn xem còn phương pháp nào nữa ko 😃

            tobi

            1 Reply Last reply Reply Quote 0
            • manhhip94
              manhhip94 @jokyspy last edited by

              @jokyspy .. Anh ơi cho em hỏi... tại sao em đọc 1 số code cũng như code của anh em thấy moi người đều lưu trữ session trong database, hay như trong code mình tạo 1 store và tạo mới 1 mongoStore ... anh có thể giải thích rõ hơn 1 chút về phần lưu trữ này được không ạ 😃 !

              nguyenmanh94!!!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              $(document).ready(function () { app.coldLoad(); }); }