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.appfunction in yourapp.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.appfunction in yourapp.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
nametofalse. This is equivalent to callingapp.set(name, false).Parameters:
Name Type Description namestring Name of the setting
Returns:
this
- Type
- App
Example
app.disable('something'); app.get('something'); // => false -
disabled(name)
-
Returns true if the boolean setting
nameis disabled (false).Parameters:
Name Type Description namestring 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
nametotrue. This is equivalent to callingapp.set(name, true).Parameters:
Name Type Description namestring Name of the setting
Returns:
this
- Type
- App
Example
app.enable('something'); app.get('something'); // => true -
enabled(name)
-
Returns true if the boolean setting
nameis enabled (true).Parameters:
Name Type Description namestring 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 namestring 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
nametovalue.Parameters:
Name Type Description namestring 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'