Reputation: 6680
I am new to Node.js and server-side JS in general.
I am coming from Java EE and I am used to use stateful objects (not EJB, I am using CDI), for instance, for MVC. My aim is to keep some data that is tied to e.g. a session.
CDI in Java EE knows the following state scopes:
How to do all that stuff with Node without using a database, just using stateful objects?
Upvotes: 2
Views: 4620
Reputation: 85341
Just like in the Java world, to be scalable, you'd need either server affinity or an external store for session data. Storing session scoped data on the server (as well as replicating it across all clones) is not scalable.
Upvotes: 1
Reputation: 146014
You'll need something like connect to track session state for you as that is the least-trivial of these scopes. Once you have that you can do things as follows.
myServer.totalRequestsServed = 0
global.totalRequestsServed = 0
req.session.user = myUser
session.user.shoppingCart = {}
req.flash("Welcome!")
. See connect-flash for example.Upvotes: 2