res.location()

res.location(path) Sets the response Location HTTP header to the specified path parameter. res.location('/foo/bar'); res.location('http://example.com'); res.location('back'); A path value of “back” has a special meaning, it refers to the URL specified in the Referer header of the request. If the Referer header was not specified, it refers to “/”. Express passes the specified URL string as-is to the browser in the Location header, without any validation or manipulation, except in case of back.

res.locals

res.locals An object that contains response local variables scoped to the request, and therefore available only to the view(s) rendered during that request / response cycle (if any). Otherwise, this property is identical to app.locals. This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on. app.use(function(req, res, next){ res.locals.user = req.user; res.locals.authenticated = ! req.user.anonymous; next()

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"

res.jsonp()

res.jsonp([body]) Sends a JSON response with JSONP support. This method is identical to res.json(), except that it opts-in to JSONP callback support. res.jsonp(null); // => null res.jsonp({ user: 'tobi' }); // => { "user": "tobi" } res.status(500).jsonp({ error: 'message' }); // => { "error": "message" } By default, the JSONP callback name is simply callback. Override this with the jsonp callback name setting. The following are some examples of JSONP responses using the same code: /

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

res.headersSent Boolean property that indicates if the app sent HTTP headers for the response. app.get('/', function (req, res) { console.log(res.headersSent); // false res.send('OK'); console.log(res.headersSent); // true });

res.get()

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

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

res.end()

res.end([data] [, encoding]) Ends the response process. This method actually comes from Node core, specifically the response.end() method of http.ServerResponse. Use to quickly end the response without any data. If you need to respond with data, instead use methods such as res.send() and res.json(). res.end(); res.status(404).end();

res.download()

res.download(path [, filename] [, fn]) Transfers the file at path as an “attachment”. Typically, browsers will prompt the user for download. By default, the Content-Disposition header “filename=” parameter is path (this typically appears in the browser dialog). Override this default with the filename parameter. When an error ocurrs or transfer is complete, the method calls the optional callback function fn. This method uses res.sendFile() to transfer the file. res.download('/report-12345.pdf');