0
res.type(mime.lookup(path)) -> res is a type of express.Response
res.setHeader('Content-Type', mime.lookup(path))

Can I know are above two lines the same?

bunny
  • 1,797
  • 8
  • 29
  • 58

2 Answers2

1

You can test by calling api from client or using log on server, check more View Express JS response headers?

buithienquyet
  • 351
  • 1
  • 6
1

Yes it has same functionality to set Content-Type to response header.

Here documentation for res.type

https://expressjs.com/en/api.html#res.type

And here documentation for res.set

https://expressjs.com/en/api.html#res.set

  • I found the res.type is adding the charset at the end but the set is not. Is it possible to get the charset as well? – bunny Feb 18 '22 at 01:27