Used to get all registered routes in Express Application
Special-cased "all" method, applying the given route path
,
middleware, and callback to every HTTP method.
The app.mountpath property contains one or more path patterns on which a sub-app was mounted.
The app.routes object houses all of the routes defined mapped by the associated HTTP verb. This object may be used for introspection capabilities, for example Express uses this internally not only for routing but to provide default OPTIONS behaviour unless app.options() is used. Your application or framework may also remove routes by simply by removing them from this object.
Stack of configured routes
Initialize application configuration.
Disable setting
.
Check if setting
is disabled.
app.disabled('foo') // => true
app.enable('foo') app.disabled('foo') // => false
Enable setting
.
Check if setting
is enabled (truthy).
app.enabled('foo') // => false
app.enable('foo') app.enabled('foo') // => true
Register the given template engine callback fn
as ext
.
By default will require()
the engine based on the
file extension. For example if you try to render
a "foo.jade" file Express will invoke the following internally:
app.engine('jade', require('jade').__express);
For engines that do not provide .__express
out of the box,
or if you wish to "map" a different extension to the template engine
you may use this method. For example mapping the EJS template engine to
".html" files:
app.engine('html', require('ejs').renderFile);
In this case EJS provides a .renderFile()
method with
the same signature that Express expects: (path, options, callback)
,
though note that it aliases this method as ejs.__express
internally
so if you're using ".ejs" extensions you dont need to do anything.
Some template engines do not follow this convention, the Consolidate.js library was created to map all of node's popular template engines to follow this convention, thus allowing them to work seamlessly within Express.
Initialize the server.
Listen for connections.
A node http.Server
is returned, with this
application (which is a Function
) as its
callback. If you wish to create both an HTTP
and HTTPS server you may do so with the "http"
and "https" modules as shown here:
var http = require('http') , https = require('https') , express = require('express') , app = express();
http.createServer(app).listen(80); https.createServer({ ... }, app).listen(443);
The mount event is fired on a sub-app, when it is mounted on a parent app. The parent app is passed to the callback function.
NOTE: Sub-apps will:
Map the given param placeholder name
(s) to the given callback(s).
Parameter mapping is used to provide pre-conditions to routes which use normalized placeholders. For example a :user_id parameter could automatically load a user's information from the database without any additional code,
The callback uses the samesignature as middleware, the only differencing
being that the value of the placeholder is passed, in this case the id
of the user. Once the next()
function is invoked, just like middleware
it will continue on to execute the route, or subsequent parameter functions.
app.param('user_id', function(req, res, next, id){
User.find(id, function(err, user){
if (err) {
next(err);
} else if (user) {
req.user = user;
next();
} else {
next(new Error('failed to load user'));
}
});
});
Alternatively, you can pass only a callback, in which case you have the opportunity to alter the app.param()
Return the app's absolute pathname based on the parent(s) that have mounted it.
For example if the application was mounted as "/admin", which itself was mounted as "/blog" then the return value would be "/blog/admin".
Render the given view name
name with options
and a callback accepting an error and the
rendered template string.
Example:
app.render('email', { name: 'Tobi' }, function(err, html){ // ... })
Assign setting
to val
, or return setting
's value.
app.set('foo', 'bar'); app.get('foo'); // => "bar" app.set('foo', ['bar', 'baz']); app.get('foo'); // => ["bar", "baz"]
Mounted servers inherit their parent server's settings.
Express instance itself is a request handler, which could be invoked without third argument.