0

How can I put the server IP address when I connect to the server in the frontend?

var socket = io.connect('http://localhost:3000/panel'); 

So instead localhost put the correspondent server IP address for the production environment.

Thanks.

4
  • Yes that's all. Or you put the hostname instead of the IP. Commented Jan 11, 2018 at 15:06
  • So, it is not possible to detect automatically the IP or the hostname? Commented Jan 11, 2018 at 15:15
  • Works like a charm!! Thanks...it was easy yes but sometimes you do not see the solution :( Commented Jan 11, 2018 at 15:38
  • In a production environment, you would typically refer to a DNS hostname such as http://www.google.com though you would of course use your own registered DNS name. Commented Jan 11, 2018 at 23:48

1 Answer 1

1

Since this Javascript is executing in the client, you can just do the following:

document.location.hostname contains the hostname, and document.location.port the port. It's as easy as that.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.