# Work with HTTP headers in Express

> Learn how to read and change HTTP headers in Express using req.headers, req.header() to get one value, res.set() to set a header, and the res.type() shortcut.

Author: Flavio Copes | Published: 2018-09-19 | Canonical: https://flaviocopes.com/express-headers/

## Access HTTP headers values from a request

You can access all the HTTP headers using the `Request.headers` property:

```js
app.get('/', (req, res) => {
  console.log(req.headers)
})
```

Use the `Request.header()` method to access one individual request header's value:

```js
app.get('/', (req, res) => {
  req.header('User-Agent')
})
```

## Change any HTTP header value for a response

You can change any HTTP header value using `Response.set()`:

```js
res.set('Content-Type', 'text/html')
```

There is a shortcut for the Content-Type header, however:

```js
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:
```

If you're not sure what a response header does, paste your headers into my [HTTP headers explainer tool](https://flaviocopes.com/tools/headers-explainer/) and it will explain each one.
