Explain how to achieve session management in Node.js applications.
Instruction: Discuss the techniques for managing sessions in Node.js, including the use of external stores.
Context: This question tests the candidate's ability to implement session management, critical for maintaining state in stateless HTTP transactions.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
A common server-side session design stores an opaque session ID in a browser cookie and stores session data on the server. express-session provides this middleware pattern; Node core does not automatically provide a complete application session policy.
Use a production-suitable shared store when requests can reach different workers. The middleware's default MemoryStore is for development and is unsuitable for production. Select a store based on latency, expiry semantics, availability and operational requirements...