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 template engines with Express

A template engine enables you to use static template files in your application. At runtime, the template engine replaces variables in a template file with actual values, and transforms the template into an HTML file sent to the client. This approach makes it easier to design an HTML page. Some popular template engines that work with Express are Pug, Mustache, and EJS. The Express application generator uses Pug as its default, but it also supports several others. See Template Engines (Express wi

req.subdomains

req.subdomains An array of subdomains in the domain name of the request. // Host: "tobi.ferrets.example.com" req.subdomains // => ["ferrets", "tobi"]

FAQ

How should I structure my application? There is no definitive answer to this question. The answer depends on the scale of your application and the team that is involved. To be as flexible as possible, Express makes no assumptions in terms of structure. Routes and other application-specific logic can live in as many files as you wish, in any directory structure you prefer. View the following examples for inspiration: Route listings Route map MVC style controllers Also, there are third-party ex

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

res.json()

res.json([body]) Sends a JSON response. This method is identical to res.send() with an object or array as the parameter. However, you can use it to convert other values to JSON, such as null, and undefined (although these are technically not valid JSON). res.json(null); res.json({ user: 'tobi' }); res.status(500).json({ error: 'message' });

res.attachment()

res.attachment([filename]) Sets the HTTP response Content-Disposition header field to “attachment”. If a filename is given, then it sets the Content-Type based on the extension name via res.type(), and sets the Content-Disposition “filename=” parameter. res.attachment(); // Content-Disposition: attachment res.attachment('path/to/logo.png'); // Content-Disposition: attachment; filename="logo.png" // Content-Type: image/png

req.method

req.method Contains a string corresponding to the HTTP method of the request: GET, POST, PUT, and so on.

req.param()

req.param(name [, defaultValue]) Deprecated. Use either req.params, req.body or req.query, as applicable. Returns the value of param name when present. // ?name=tobi req.param('name') // => "tobi" // POST name=tobi req.param('name') // => "tobi" // /user/tobi for /user/:name req.param('name') // => "tobi" Lookup is performed in the following order: req.params req.body req.query Optionally, you can specify defaultValue to set a default value if the parameter is not found in any o