Home > OS >  express.Response setHeader for content type and type function
express.Response setHeader for content type and type function

Time:02-17

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?

CodePudding user response:

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

CodePudding user response:

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

  • Related