Response Object Flashcards
res.status(code)
Sets the HTTP status code
res.set(name, value)
Sets a response header
res.cookie(name, value, [options])
Sets a cookie that will be stored on the client
res.clearCookie(name, [options])
Clears a cookie stored on the client
res.redirect([status], url)
Redirects a browser. Default redirect code is 302
res.send(status, body)
Sends a response to the client with optional status code
res.json(staus, json)
Sends JSON to the client with optional status code
res.jsonp(status, json)
Sends JSONP to the client with optional status code
res.type(type)
A convenience method to set the Content-Type header. Equivalent to res.set(‘Content-Type’, type) except it maps a file extension to an Internet media type if you provide a type without a slash in it. For instance res.type(‘text’)
res.format(object)
Allows you to send different content depending on the Accept request header
res.attachment([filename])
Sets Content-Disposition header to ‘attachment’ causing browser to prompt to download rather than display a file. filename serves as hint to browser
res.download(path, [filename], [callback])
Sets Content-Disposition header to ‘attachment,’ causing browser to prompt to download rather than display a file.
Allows you to specify a file to download
res.sendFile(path, [options], [callback])
Read a file specified by path and send its content to the client
res.links(links)
Sets the Links response header
res.locals
Object containing the default context for rendering views