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

  • SEARCH
  • Home
  • 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 9008499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:57:05+00:00 2026-06-16T01:57:05+00:00

Trying to write some helper methods for an express 3.0 app. Here is an

  • 0

Trying to write some helper methods for an express 3.0 app. Here is an example to greet the user:

  app.locals.greet = function(req,res) {
    return "hey there " + req.user.name;
  }

However, req and res aren’t available inside that function. How would I go about writing helpers that I can use inside my jade templates? Am I doing this wrong?

  • 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-16T01:57:06+00:00Added an answer on June 16, 2026 at 1:57 am

    Have a look at my config app.js file! that should work to you as the variables will e available at that context.

    app.configure(function(){
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade');
    
    app.use(connect.compress());
    app.use(express.static(__dirname + "/public", { maxAge: 6000000 }));
    app.use(express.favicon(__dirname + "/public/img/favicon.ico", { maxAge: 6000000 }));
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(express.cookieParser());
    app.use(express.session({
        secret: config.sessionSecret,
        maxAge: new Date(Date.now() + (1000 * 60 * 15)),
        store: new MongoStore({ url: config.database.connectionString })
    }));
    app.use(function(req, res, next){
        console.log("\n~~~~~~~~~~~~~~~~~~~~~~~{   REQUEST   }~~~~~~~~~~~~~~~~~~~~~~~".cyan);
        res.locals.config = config;
        res.locals.session = req.session;
        res.locals.utils = viewUtils;
            res.locals.greet = function(){
                    //req and res are available here!
                    return "hey there " + req.user.name;
            };
        next();
    });
    app.use(app.router);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I spent some time trying to write a 'helper' macro to test a parameter
I'm trying to write some parameter wrapping helper code like below #include <type_traits> #include
I am trying to write Haskell FFI binding for some C structs. An example
I'm trying to write a custom Javascript MVC3 Helper class foe my project, and
I am trying to write a Browser Helper Object (BHO) in C# that manipulates
I'm trying to have an table in text mail, so I write some helpers:
I'm trying to write a helper method in JavaScript. It should act differently if
I am trying to write a function (lnn; list-not-nil) similar to list that only
Trying to write a test for a helper method that uses acts_as_tree. Helper method
I'm trying to write a helper script for doing various admin tasks on a

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.