res.type(type) sets the response Content-Type header. If type contains /, Express uses that string as-is. Otherwise it treats type as a file extension and looks up the MIME type with the mime-types package.
It is aliased as res.contentType(). Call it before you send the body with res.send(), res.end(), or similar. Methods like res.json() may set Content-Type for you.
Syntax
Call res.type in your Express.js app. Start with this line.
Express
res.type(type)
res.contentType(type) // alias
Call
What it does
res.type(type)
Primary signature.
res.contentType(type) // alias
Related call form.
Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.
GET /pixel.png
Content-Type: image/png
Body: (binary PNG, 1×1 pixel)
How It Works
Extension lookup.'png' maps to image/png.
Chain send.type returns res, so .send(png) follows.
Buffer body. Binary is sent with the type you chose.
Alias works too.res.contentType('png') is the same call.
Compatibility
Runtime Support
res.type() is an Express.js response method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only receive the Content-Type on the HTTP response.
✓ Server · Express 4 & 5
res.type()
Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.
ServerNode.js runtime API
Node.js18+ for Express 5 · 14+ typical for Express 4
Supported
BunExpress-compatible server apps
Supported
DenoVia npm compatibility / adapters
Supported
res.type()Express on Node.js
Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.
Frequently Asked Questions
It sets the Content-Type response header. If the argument contains a slash, it is used as-is; otherwise Express looks up a MIME type from a file extension via the mime-types package.
No. res.contentType() is an alias of res.type() and behaves the same way.
No. It only sets the header. Finish with res.send(), res.end(), or another response method.
Use res.set when you need an exact header string (including unusual parameters). Prefer res.type for short extensions like json or html.
No. It runs on your Node.js server. Browsers only receive the Content-Type on the HTTP response.