5

I am quite new to Express.js/Node.js and trying to pass multiple values from a route to a view so that I am able to show user specific input on the page. This is what I have in my route:

// Dashboard for site after the login
app.get('/dashboard', function(req, res) {
 res.render('dashboard.jade', {
  title: 'Dashboard',
  user: app.get('user_name')
 });
});

I have stored the user name in app.get('user_name'). If I replace it with a normal string like 'test string' than it works. But if I use this app.get function nothing is getting passed to the view.

Thanks

1 Answer 1

4

Try using app.locals documented here: http://expressjs.com/api.html#app.locals

Sign up to request clarification or add additional context in comments.

1 Comment

i tried using app.locals and then switched back using app.get / app.set somehow it was working after i have restarted nodemon ;-) but i agree most likely app.locals would be the better choice. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.