Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

373
Views
Socket.io chat application working only on localhost

I'm completely new to web sockets and javascript. I'm trying to create a chat application using javascript and socket.io. It works on localhost (using "npm start" command line).

My question is: how can I access it from any other PC and use it like a real chat application?

I have the following error when I don't access it on localhost:

error

How can I host it for free and access it from anywhere? Can someone provide me an example of a socket.io chat application and step-by-step instructions?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It does not work because if you are accessing to your website not from localhost, your hostname will not be the server address. So, in your var socket = io(); you can specify the url that the user is accessing your website from.

Like this:

// get the url
let url = window.location.href.split("/");
url = url[0] + "//" + url[2];

const socket = io(url);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!