Skip to content

Express response.type

TIP

将 Content-Type HTTP 标头设置为由指定 type 确定的 MIME 类型。

Express
res.type(type)

将 Content-Type HTTP 标头设置为由指定 type 确定的 MIME 类型。如果 type 包含 "/" 字符,则它将 Content-Type 设置为 type 的确切值,否则假定它是文件扩展名并使用 express.static.mime.lookup() 方法在映射中查找 MIME 类型。

Express
res.type('.html') // => 'text/html'
res.type('html') // => 'text/html'
res.type('json') // => 'application/json'
res.type('application/json') // => 'application/json'
res.type('png') // => image/png: