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)
- Start Socket.IO server (serves build in production mode):
cd server
npm install
npm start- 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 startOpen from another device (phone) on same Wi-Fi:
- Visit http://<DEV_IP>:3000 where <DEV_IP> is your machine local IP (run hostname -Ior see the "On Your Network" address printed by CRA).
Production-like (serve built client + socket on single port)
- Build the client:
cd client
npm run build- Start the server that will serve the built client and Socket.IO on the same origin:
cd server
npm install
npm start- Open locally:
- http://localhost:3001 (or the port the server logs)
Share publicly (short-lived) — localtunnel
- After step 2 above (server is running), start localtunnel in the serverfolder:
cd server
# request a subdomain or let localtunnel choose one
npx localtunnel --port 3001 --subdomain my-react-chat
# OR
npx localtunnel --port 3001- localtunnel prints a public URL (https://.loca.lt). Share that URL.
Share publicly (recommended) — ngrok (persistent HTTPS)
- Install ngrok and authenticate with your token (ngrok signup required):
# download and install ngrok, then:
ngrok authtoken <your-token>
ngrok http 3001- 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'andkill <PID>.
- Localhost vs LAN IP not reachable: ensure client/.envcontainsHOST=0.0.0.0and the dev server prints the LAN address. Check firewall (egsudo ufw allow 3000/tcpandsudo 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 startSecurity 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 sharescript that starts localtunnel automatically and prints the public URL.
- Add a small systemd or pm2 config to keep the server running persistently.