Express.js Response Complete Reference (original) (raw)

Last Updated : 23 Jul, 2025

Express.js is a small framework that works on top of Node.js web server functionality to simplify its APIs and add helpful new features. It makes it easier to organize your application’s functionality with middleware and routing.

Express.js Response Properties:

Properties Description
Express.js res.app Property The res.app property holds a reference to the instance of the Express application that is using the middleware.
Express.js res.headersSent Property The res.headersSent property is a boolean property that indicates if the app sent HTTP headers for the response.
Express.js res.locals Property The res.locals property is an object that contains response local variables scoped to the request and because of this, it is only available to the view(s) rendered during that request/response cycle (if any).

Express.js Response Methods:

Methods Description
Express.js res.append() Function The res.append() function appends the specified value to the HTTP response header field and if the header is not already set then it creates the header with the specified value.
Express.js res.attachment() Function The res.attachment() function is used to set the HTTP response Content-Disposition header field to ‘attachment’. If the name of the file is given as a filename then it sets the Content-Type based on the extension name through the res.type() function and finally sets the Content-Disposition ‘filename = ‘ parameter.
Express.js res.cookie() Function The res.cookie() function is used to set the cookie name to value. The value parameter may be a string or object converted to JSON.
Express.js res.clearCookie() Function The res.clearCookie() function is used to clear the cookie specified by name. This function is called for clearing the cookies which as already been set.
Express.js res.download() Function The res.download() function transfers the file at the path as an ‘attachment’. Typically, browsers will prompt the user to download.
Express.js res.end() Function The res.end() function is used to end the response process. This method actually comes from the Node core, specifically the response.end() method of HTTP.ServerResponse.
Express.js res.format() Function The res.format() function performs content negotiation on the Accept HTTP header on the request object if it is present.
Express.js res.get() Function The res.get() function returns the HTTP response header specified by the field. The match is case-insensitive.
Express.js res.json() Function The res.json() function sends a JSON response. This method sends a response (with the correct content-type) that is the parameter converted to a JSON string using the JSON.stringify() method.
Express.js res.jsonp() Function The res.jsonp() function is used to send a JSON response with JSONP support and this function is similar to the res.json() function except that it opts-in to the support of JSONP callback.
Express.js res.links() Function The res.links() function is used to join the links provided as properties of the parameter to populate the response’s Link HTTP header field.
Express.js res.location() Function The res.location() function is used to set the response Location HTTP header to the path parameter which is being specified. Basically, it is used to set the response header.
Express.js res.redirect() Function The res.redirect() function redirects to the URL derived from the specified path, with specified status, an integer (positive) which corresponds to an HTTP status code.
Express.js res.render() Function The res.render() function is used to render a view and sends the rendered HTML string to the client.
Express.js res.send() Function The res.send() function basically sends the HTTP response. The body parameter can be a String or a Buffer object or an object or an Array.
Express.js res.sendFile() Function The res.sendFile() function basically transfers the file at the given path and it sets the Content-Type response HTTP header field based on the filename extension.
Express.js res.sendStatus() Function The res.sendStatus() function is used to set the response HTTP status code to statusCode and send its string representation as the response body.
Express.js res.set() Function The res.set() function is used to set the response HTTP header field to value. To set multiple fields at once, pass an object as the parameter.
Express.js res.status() Function The res.status() function set the HTTP status for the response. It is a chainable alias of Node’s response.statusCode.
Express.js res.type() Function The res.type() function is used to set the Content-Type HTTP header to the MIME type determined by the mime.lookup() function for the specified type.
Express.js res.vary() Function The res.vary() function is used to add the field to the Vary response header, if it is not there already. The Vary header indicates which headers it’s basically used for content negotiation.