app.use()

app.use([path,] function [, function...]) Mounts the specified middleware function or functions at the specified path. If path is not specified, it defaults to “/”. A route will match any path that follows its path immediately with a “/”. For example: app.use('/apple', ...) will match “/apple”, “/apple/images”, “/apple/images/news”, and so on. Note that req.originalUrl in a middleware function is a combination of req.baseUrl and req.path, as shown in the following example. app.use('/admin', f

app.set()

app.set(name, value) Assigns setting name to value, where name is one of the properties from the app settings table. Calling app.set('foo', true) for a Boolean property is the same as calling app.enable('foo'). Similarly, calling app.set('foo', false) for a Boolean property is the same as calling app.disable('foo'). Retrieve the value of a setting with app.get(). app.set('title', 'My Site'); app.get('title'); // "My Site" Application Settings The following table lists application settings. Not

app.render()

app.render(view, [locals], callback) Returns the rendered HTML of a view via the callback function. It accepts an optional parameter that is an object containing local variables for the view. It is like res.render(), except it cannot send the rendered view to the client on its own. Think of app.render() as a utility function for generating rendered view strings. Internally res.render() uses app.render() to render views. The local variable cache is reserved for enabling view cache. Set it to

app.route()

app.route(path) Returns an instance of a single route, which you can then use to handle HTTP verbs with optional middleware. Use app.route() to avoid duplicate route names (and thus typo errors). var app = express(); app.route('/events') .all(function(req, res, next) { // runs for all HTTP verbs first // think of it as route specific middleware! }) .get(function(req, res, next) { res.json(...); }) .post(function(req, res, next) { // maybe add a new event... });

app.put()

app.put(path, callback [, callback ...]) Routes HTTP PUT requests to the specified path with the specified callback functions. For more information, see the routing guide. You can provide multiple callback functions that behave just like middleware, except that these callbacks can invoke next('route') to bypass the remaining route callback(s). You can use this mechanism to impose pre-conditions on a route, then pass control to subsequent routes if there’s no reason to proceed with the current r

app.post()

app.post(path, callback [, callback ...]) Routes HTTP POST requests to the specified path with the specified callback functions. For more information, see the routing guide. You can provide multiple callback functions that behave just like middleware, except that these callbacks can invoke next('route') to bypass the remaining route callback(s). You can use this mechanism to impose pre-conditions on a route, then pass control to subsequent routes if there’s no reason to proceed with the current

app.path()

app.path() Returns the canonical path of the app, a string. var app = express() , blog = express() , blogAdmin = express(); app.use('/blog', blog); blog.use('/admin', blogAdmin); console.log(app.path()); // '' console.log(blog.path()); // '/blog' console.log(blogAdmin.path()); // '/blog/admin' The behavior of this method can become very complicated in complex cases of mounted apps: it is usually better to use req.baseUrl to get the canonical path of the app.

app.param()

app.param([name], callback) Add callback triggers to route parameters, where name is the name of the parameter or an array of them, and callback is the callback function. The parameters of the callback function are the request object, the response object, the next middleware, the value of the parameter and the name of the parameter, in that order. If name is an array, the callback trigger is registered for each parameter declared in it, in the order in which they are declared. Furthermore, for

app.mountpath

app.mountpath The app.mountpath property contains one or more path patterns on which a sub-app was mounted. A sub-app is an instance of express that may be used for handling the request to a route. var express = require('express'); var app = express(); // the main app var admin = express(); // the sub app admin.get('/', function (req, res) { console.log(admin.mountpath); // /admin res.send('Admin Homepage'); }); app.use('/admin', admin); // mount the sub app It is similar to the baseU

app.on()

app.on('mount', callback(parent)) 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: Not inherit the value of settings that have a default value. You must set the value in the sub-app. Inherit the value of settings with no default value. For details, see Application settings. var admin = express(); admin.on('mount', function (parent) { console.log('Admin Mounted'); console.log(parent); // refer