Class: App

App

App


new App(props)

Do not initialize this class on your own. An instance of this class is accessible via req.app and res.app.

Parameters:
Name Type Description
props Object

Members


<readonly> locals :Object

Object available to all functions. You can set properties in this object in your exports.app function in your app.js. However, the object is then turned read-only and can no longer be modified.

Type:
  • Object
Example
// app.js
exports.app = function(app) {
  app.locals.title = 'ZomboCom';
  app.locals.tagline = 'You can do anything at ZomboCom.';
};
// your function
exports.handle = function(req, res) {
  req.app.locals.title // => 'ZomboCom'
  req.app.locals.newProp = 'not allowed'; // Not allowed. Properties can only be set in `exports.app` function in `app.js`.
};

<readonly> settings :Object

Settings for your application. You can set settings using res.set() function in your exports.app function in your app.js. The settings object is then turned read-only and can no longer be modified.

Type:
  • Object
Example
// app.js
exports.app = function(app) {
  app.set('x-powered-by', false);
};
// your function
exports.handle = function(req, res) {
  req.app.get('x-powered-by') // => false
  req.app.set('newProp', 'not allowed'); // Not allowed. Settings can only be set in `exports.app` function in `app.js`.
};

Methods


disable(name)

Sets the value of the boolean setting name to false. This is equivalent to calling app.set(name, false).

Parameters:
Name Type Description
name string

Name of the setting

Returns:

this

Type
App
Example
app.disable('something');
app.get('something'); // => false

disabled(name)

Returns true if the boolean setting name is disabled (false).

Parameters:
Name Type Description
name string

Name of the setting

Returns:
Type
boolean
Example
app.disable('something');
app.disabled('something'); // => true
app.enabled('something'); // => false

enable(name)

Sets the value of the boolean setting name to true. This is equivalent to calling app.set(name, true).

Parameters:
Name Type Description
name string

Name of the setting

Returns:

this

Type
App
Example
app.enable('something');
app.get('something'); // => true

enabled(name)

Returns true if the boolean setting name is enabled (true).

Parameters:
Name Type Description
name string

Name of the setting

Returns:
Type
boolean
Example
app.enable('something');
app.enabled('something'); // => true
app.disabled('something'); // => false

get(name)

Gets the value of the setting name.

Parameters:
Name Type Description
name string

Name of the setting

Returns:

Value of the setting

Type
*
Example
app.set('title', 'My Awesome App');
app.get('title'); // => 'My Awesome App'

set(name, value)

Sets setting name to value.

Parameters:
Name Type Description
name string

Name of the setting

value *

Value of the setting

Returns:

this

Type
App
Example
app.set('title', 'My Awesome App');
app.get('title'); // => 'My Awesome App'