req.hostname

req.hostname Contains the hostname derived from the Host HTTP header. When the trust proxy setting does not evaluate to false, this property will instead have the value of the X-Forwarded-Host header field. This header can be set by the client or by the proxy. // Host: "example.com:3000" req.hostname // => "example.com"

Using middleware

Express is a routing and middleware web framework that has minimal functionality of its own: An Express application is essentially a series of middleware function calls. 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 co

req.get()

req.get(field) Returns the specified HTTP request header field (case-insensitive match). The Referrer and Referer fields are interchangeable. req.get('Content-Type'); // => "text/plain" req.get('content-type'); // => "text/plain" req.get('Something'); // => undefined Aliased as req.header(field).

res.get()

res.get(field) Returns the HTTP response header specified by field. The match is case-insensitive. res.get('Content-Type'); // => "text/plain"

router.METHOD()

router.METHOD(path, [callback, ...] callback) The router.METHOD() methods provide the routing functionality in Express, where METHOD is one of the HTTP methods, such as GET, PUT, POST, and so on, in lowercase. Thus, the actual methods are router.get(), router.post(), router.put(), and so on. You can provide multiple callbacks, and all are treated equally, and behave just like middleware, except that these callbacks may invoke next('route') to bypass the remaining route callback(s). You can use

app.get()

app.get(name) Returns the value of name app setting, where name is one of strings in the app settings table. For example: app.get('title'); // => undefined app.set('title', 'My Site'); app.get('title'); // => "My Site"

req.acceptsLanguages()

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

Error handling

Define error-handling middleware functions in the same way as other middleware functions, except error-handling functions have four arguments instead of three: (err, req, res, next). For example: app.use(function(err, req, res, next) { console.error(err.stack); res.status(500).send('Something broke!'); }); You define error-handling middleware last, after other app.use() and routes calls; for example: var bodyParser = require('body-parser'); var methodOverride = require('method-override');

app.enabled()

app.enabled(name) Returns true if the setting name is enabled (true), where name is one of the properties from the app settings table. app.enabled('trust proxy'); // => false app.enable('trust proxy'); app.enabled('trust proxy'); // => true

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.