app.disable()

app.disable(name) Sets the Boolean setting name to false, where name is one of the properties from the app settings table. Calling app.set('foo', false) for a Boolean property is the same as calling app.disable('foo'). For example: app.disable('trust proxy'); app.get('trust proxy'); // => false

app.locals

app.locals The app.locals object has properties that are local variables within the application. app.locals.title // => 'My App' app.locals.email // => 'me@myapp.com' Once set, the value of app.locals properties persist throughout the life of the application, in contrast with res.locals properties that are valid only for the lifetime of the request. You can access local variables in templates rendered within the application. This is useful for providing helper functions to templates, as

res.links()

res.links(links) Joins the links provided as properties of the parameter to populate the response’s Link HTTP header field. For example, the following call: res.links({ next: 'http://api.example.com/users?page=2', last: 'http://api.example.com/users?page=5' }); Yields the following results: Link: <http://api.example.com/users?page=2>; rel="next", <http://api.example.com/users?page=5>; rel="last"

Express behind proxies

When running an Express app behind a proxy, set (by using app.set()) the application variable trust proxy to one of the values listed in the following table. Although the app will not fail to run if the application variable trust proxy is not set, it will incorrectly register the proxy’s IP address as the client IP address unless trust proxy is configured. Type Value Boolean If true, the client’s IP address is understood as the left-most entry in the X-Forwarded-* header. If false, the app i

express.Router()

express.Router([options]) Creates a new router object. var router = express.Router([options]); The optional options parameter specifies the behavior of the router. Property Description Default Availability caseSensitive Enable case sensitivity. Disabled by default, treating “/Foo” and “/foo” as the same. mergeParams Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. false 4.5.0+ strict Enable st

res.send()

res.send([body]) Sends the HTTP response. The body parameter can be a Buffer object, a String, an object, or an Array. For example: res.send(new Buffer('whoop')); res.send({ some: 'json' }); res.send('<p>some html</p>'); res.status(404).send('Sorry, we cannot find that!'); res.status(500).send({ error: 'something blew up' }); This method performs many useful tasks for simple non-streaming responses: For example, it automatically assigns the Content-Length HTTP response header field

app.delete()

app.delete(path, callback [, callback ...]) Routes HTTP DELETE 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 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

res.format()

res.format(object) Performs content-negotiation on the Accept HTTP header on the request object, when present. It uses req.accepts() to select a handler for the request, based on the acceptable types ordered by their quality values. If the header is not specified, the first callback is invoked. When no match is found, the server responds with 406 “Not Acceptable”, or invokes the default callback. The Content-Type response header is set when a callback is selected. However, you may alter this wi

Basic routing

Routing refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (GET, POST, and so on). Each route can have one or more handler functions, which are executed when the route is matched. Route definition takes the following structure: app.METHOD(PATH, HANDLER) Where: app is an instance of express. METHOD is an HTTP request method. PATH is a path on the server. HANDLER is the function executed

res.redirect()

res.redirect([status,] path) Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an HTTP status code . If not specified, status defaults to “302 “Found”. res.redirect('/foo/bar'); res.redirect('http://example.com'); res.redirect(301, 'http://example.com'); res.redirect('../login'); Redirects can be a fully-qualified URL for redirecting to a different site: res.redirect('http://google.com'); Redirects can be relative to the root o