req.ips

req.ips When the trust proxy setting does not evaluate to false, this property contains an array of IP addresses specified in the X-Forwarded-For request header. Otherwise, it contains an empty array. This header can be set by the client or by the proxy. For example, if X-Forwarded-For is client, proxy1, proxy2, req.ips would be ["client", "proxy1", "proxy2"], where proxy2 is the furthest downstream.

Writing middleware for use in Express apps

Overview Middleware functions are functions that have access to the request object (req), the response object (res), and the next middleware function in the application’s request-response cycle. The next middleware function is commonly denoted by a variable named next. Middleware functions can perform the following tasks: Execute any code. Make changes to the request and the response objects. End the request-response cycle. Call the next middleware in the stack. If the current middleware func

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.METHOD()

app.METHOD(path, callback [, callback ...]) Routes an HTTP request, where METHOD is the HTTP method of the request, such as GET, PUT, POST, and so on, in lowercase. Thus, the actual methods are app.get(), app.post(), app.put(), and so on. See below for the complete list. For more information, see the routing guide. Express supports the following routing methods corresponding to the HTTP methods of the same names: checkout copy delete get head lock merge mkactivity mkcol move m-search notify

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"

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.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

res.render()

res.render(view [, locals] [, callback]) Renders a view and sends the rendered HTML string to the client. Optional parameters: locals, an object whose properties define local variables for the view. callback, a callback function. If provided, the method returns both the possible error and rendered string, but does not perform an automated response. When an error occurs, the method invokes next(err) internally. The local variable cache enables view caching. Set it to true, to cache the view

req.accepts()

req.accepts(types) Checks if the specified content types are acceptable, based on the request’s Accept HTTP header field. The method returns the best match, or if none of the specified content types is acceptable, returns false (in which case, the application should respond with 406 "Not Acceptable"). The type value may be a single MIME type string (such as “application/json”), an extension name such as “json”, a comma-delimited list, or an array. For a list or array, the method returns the bes

req.acceptsEncodings()

req.acceptsEncodings(encoding [, ...]) Returns the first accepted encoding of the specified encodings, based on the request’s Accept-Encoding HTTP header field. If none of the specified encodings is accepted, returns false. For more information, or if you have issues or concerns, see accepts.