I'm using Node Express with EJS. I have a Login module which does all user session related jobs (like for login- generate token, Verify token). So in app.js before sending request to particular module I call login->controller->verifyToken
user.verifyToken - verifies the token from request header and gives me user details like name, profile pic, etc. I want to store these user details in a Global variable so that I can access it in all the pages. So I did this.
userHeader = authData.user; // without var, let
But with this I can access variable at view files (.ejs). But I cant access this variable at other module .JS files. I think reason behind this is that all view files are executed afterwards, whereas .js files get executed at the time of 'require'.