Categories
JavaScript Answers

How to set request header when making connection with JavaScript socket.io-client?

Spread the love

To set request header when making connection with JavaScript socket.io-client, we set the extraHeaders property.

For instance, we write

const socket = io("http://localhost", {
  extraHeaders: {
    Authorization: "Bearer authorization_token_here",
  },
});

to set extraHeaders to an object with the header keys-value pairs.

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 *