Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:07:14+00:00 2026-06-12T02:07:14+00:00

I was using dynamicHelpers to set some variables on every page in Express 2.

  • 0

I was using dynamicHelpers to set some variables on every page in Express 2. Now that they’re gone and I’m not sure how to do it. What is the best way to do something like this with Express 3?

app.js

app.dynamicHelpers( require('dynamicHelpers') )

dynamicHelpers.js

exports.user = function(req, res) {
    return req.user || {};
}

exports.message = function(req, res) {
    return req.flash.message || {};
}

in veiw.jade

h1= user.username
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:07:15+00:00Added an answer on June 12, 2026 at 2:07 am

    middleware example

    var app = require('express')()
      , jade = require('jade')
    
    app.set('views', __dirname + '/views')
    app.set('view engine', 'jade')  
    
    app.use(function(req,res,next){
      res.locals.user = { name : "test" }
      next()
    })
    
    app.get('*',function(req,res){
       res.render('index.jade')
    })
    
    app.listen('8001')
    

    index.jade

    !!! 5
    html
      body
        div hello #{user.name}
    

    to use req.flash try:

    var app = require('express')()
      , jade = require('jade')
    
    app.set('views', __dirname + '/views')
    app.set('view engine', 'jade')
    
    app.use(require('connect-flash')())
    
    // Expose the flash function to the view layer
    app.use(function(req, res, next) {
       res.locals.flash = req.flash.bind(req)
       next()
    })
    
    
    app.get('*',function(req,res){
       res.render('index.jade')
    })
    
    app.listen('8001')
    

    updated my answer, haven’t migrated to 3.0 yet, at https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x under View options:

    The "view options" setting is no longer necessary, app.locals are the local variables 
    merged with res.render()'s, so app.locals.pretty = true is the same as passing 
    res.render(view, { pretty: true }).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Yii, I want to delete all the rows that are not from today.
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using InteliJ IDEA , I am trying to set up multiple projects to run
I began using node.js+express combo very recently and I stumbled at a need to
Using WebViewBrush I can render web page content (it's screen shot) to e.g. Rectangle
Using PyGtk's IconView, I can set the icons to be reorderable by calling gtk.IconView.set_reorderable(True)
I'm using express framework. I want to reach session data from socket.io. I tried
I'm a newbie. I'm using a browser plugin that hits my node server, and
Using SSRS 2008 R2 I have a background process that dynamically generates RDL for
Using the new mvc4 now gives us access to use facebook oauth otb. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.