Timo Timo - 1 year ago 93
CoffeeScript Question

Making Session Data Accessible From Everywhere (In An Express.js Project)

I am using Express-Middleware in an outsourced file.

I set some session data in that outsourced file:


Now I want to access this variable in my root file (app.js), but there it is NULL.

How can I make this session data accessible from everywhere?

Answer Source

Okay. You simply declare the variable as global:


global.session = { }

Now you can reach this object from everywhere:

global.session.userId = 1

As seen here:

Global session variable in express.js route?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download