Skip to content

mohimi-coder/sample_chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

React Socket.IO Chat App — local + share

This README lists exact commands to run the app locally, test from another device on your LAN (phone), and share a public link (localtunnel/ngrok).

Prerequisites

  • Node.js (v16/18 recommended but Node 24 used here — we set NODE_OPTIONS in client scripts to work around OpenSSL differences).
  • npm (bundled with Node)
  • (Optional) localtunnel (npx localtunnel) or ngrok for public sharing.

Quick start (development)

  1. Start Socket.IO server (serves build in production mode):
cd server
npm install
npm start
  1. Start client dev server (CRA) — reachable from other devices on same LAN:
cd client
npm install
# .env contains HOST=0.0.0.0 so CRA listens on all interfaces
npm start

Open from another device (phone) on same Wi-Fi:

  • Visit http://<DEV_IP>:3000 where <DEV_IP> is your machine local IP (run hostname -I or see the "On Your Network" address printed by CRA).

Production-like (serve built client + socket on single port)

  1. Build the client:
cd client
npm run build
  1. Start the server that will serve the built client and Socket.IO on the same origin:
cd server
npm install
npm start
  1. Open locally:

Share publicly (short-lived) — localtunnel

  1. After step 2 above (server is running), start localtunnel in the server folder:
cd server
# request a subdomain or let localtunnel choose one
npx localtunnel --port 3001 --subdomain my-react-chat
# OR
npx localtunnel --port 3001
  1. localtunnel prints a public URL (https://.loca.lt). Share that URL.

Share publicly (recommended) — ngrok (persistent HTTPS)

  1. Install ngrok and authenticate with your token (ngrok signup required):
# download and install ngrok, then:
ngrok authtoken <your-token>
ngrok http 3001
  1. ngrok prints a public HTTPS URL. Share that URL.

Troubleshooting

  • EADDRINUSE on server start: kill the process using port 3001 or let the server auto-select a free port. Use ss -lptn 'sport = :3001' and kill <PID>.
  • Localhost vs LAN IP not reachable: ensure client/.env contains HOST=0.0.0.0 and the dev server prints the LAN address. Check firewall (eg sudo ufw allow 3000/tcp and sudo ufw allow 3001/tcp).
  • Socket.IO connection errors: ensure the client connects to the proper server host. The client will auto-detect the host; for forced override set REACT_APP_SERVER=<IP_OR_HOST> when starting.

Example: force socket to a specific server when running dev client

REACT_APP_SERVER=10.12.6.12 npm start

Security notes

  • Do not expose local development machines publicly for extended periods. Use tunnels only for short demos. Restrict server CORS in production.

If you want, I can:

  • Add an npm run share script that starts localtunnel automatically and prints the public URL.
  • Add a small systemd or pm2 config to keep the server running persistently.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published