LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

What is the purpose of res.type() in Express?

res.type() sets the response's Content-Type header, telling the client how to interpret the data it receives.

// JSON data
res.type('application/json');
// HTML page
res.type('text/html');
// Plain text
res.type('text/plain');

Common content types:

Type Content-Type Use
JSON application/json APIs
HTML text/html Web pages
Plain text text/plain Simple text
CSS text/css Stylesheets
JavaScript application/javascript Scripts
Images image/png, image/jpeg Images

Why it matters:

  • Browser decides how to display/process the response
  • JSON response with wrong type may not parse correctly
  • Security headers depend on content type

Shortcut: res.json() automatically sets application/json.

From Quiz: WEBT / Backend Development | Updated: Jul 14, 2026