Categories
JavaScript Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *