In sails.js, how to access session variables outside controller?
问题 In controller, it's easy. Accessing a session variables is straightforward: req.session.x = 1 However, how do I access that outside controller? Like in service? module.exports.test = function() { // No req.session here? }; 回答1: The session object in Sails isn't provided as a global; it's a property of the Request object. For server-side code that doesn't included the request as part of the scope (like services and models), you'll need to pass the request or the session along as an argument to