How to extract request HTTP headers from a request using Node.js Connect?

Sometimes, we want to extract request HTTP headers from a request using Node.js Connect.

In this article, we’ll look at how to extract request HTTP headers from a request using Node.js Connect.

How to extract request HTTP headers from a request using Node.js Connect?

To extract request HTTP headers from a request using Node.js Connect, we can use the req.headers property.

For instance, we write

const app = connect()
  .use(connect.logger('dev'))
  .use(connect.static('public'))
  .use((req, res) => {
    console.log(req.headers)
  })
  .listen(3000);

to get the request headers from the req.headers property in the 3rd middleware.

Conclusion

To extract request HTTP headers from a request using Node.js Connect, we can use the req.headers property.