Express: app.locals fails

Created on 27 Mar 2014  Â·  10Comments  Â·  Source: expressjs/express

I'm using Express 4.0.0-rc4 and trying to do the following:

var app = express();
app.locals({
   testing: true,
   appTitle: "Cool App"
});

Each time that I do that I get an error that says:

TypeError: Property 'locals' of object function (req, res, next) {
    app.handle(req, res, next);
  } is not a function

My current workaround is to do this:

app.locals.testing = true;
app.locals.appTitle = "Cool App"

Most helpful comment

Do this?

app.locals = {
  version: '0.0.2',
  name: 'ouj',
  codename: 'sidelix',
  web: {
    name: 'ouj',
    logo: 'images/logo.svg',
    url: 'ouj.com',
    secure: false,
    divider: ' • '
  },
  meta: {
    keyword: 'Ouj ji des',
    description: ['ouj','des']
  },
  dev: {
    name: 'Developers',
    url: 'dev.ouj.com',
    secure: false,
    errors: '/errors/'
  }
};

All 10 comments

@defunctzombie Sorry if it was my mistake posting the issue here. Was there a better place I should have put it?

It isn't an issue. This is by design. If there is some api docs saying otherwise then that is the issue.

@defunctzombie Would you like me to open a new issue regarding the documentation at http://expressjs.com/4x/api.html#app.locals then?

Yep! That would be appreciated.
On Mar 27, 2014 9:35 AM, "Clay Diffrient" [email protected] wrote:

@defunctzombie https://github.com/defunctzombie Would you like me to
open a new issue regarding the documentation at
http://expressjs.com/4x/api.html#app.locals then?

Reply to this email directly or view it on GitHubhttps://github.com/visionmedia/express/issues/2010#issuecomment-38802666
.

We should also add this to the migration guide.

Why cannot be used first one type.
I have there many sub items and the second is terrible.
Can somebody fix it?

@max258 I'm sorry, but I'm not sure what you are asking.

Is it possible use somethin as:

app.locals({
  version: '0.0.2',
  name: 'ouj',
  codename: 'sidelix',
  web: {
    name: 'ouj',
    logo: 'images/logo.svg',
    url: 'ouj.com',
    secure: false,
    divider: ' • '
  },
  meta: {
    keyword: 'Ouj ji des',
    description: ['ouj','des']
  },
  dev: {
    name: 'Developers',
    url: 'dev.ouj.com',
    secure: false,
    errors: '/errors/'
  }
});

Do this?

app.locals = {
  version: '0.0.2',
  name: 'ouj',
  codename: 'sidelix',
  web: {
    name: 'ouj',
    logo: 'images/logo.svg',
    url: 'ouj.com',
    secure: false,
    divider: ' • '
  },
  meta: {
    keyword: 'Ouj ji des',
    description: ['ouj','des']
  },
  dev: {
    name: 'Developers',
    url: 'dev.ouj.com',
    secure: false,
    errors: '/errors/'
  }
};

Thank you it works! Really nice solution

Was this page helpful?
0 / 5 - 0 ratings

Related issues

haider0324 picture haider0324  Â·  3Comments

ZeddYu picture ZeddYu  Â·  3Comments

extensionsapp picture extensionsapp  Â·  3Comments

dmaks9 picture dmaks9  Â·  3Comments

AndrewEQ picture AndrewEQ  Â·  4Comments