This workspace contains a prototype MERN application for playing the two-player NIM game in real-time using Socket.IO.
Folders:
backend— Express + Socket.IO server (in-memory game rooms)frontend— Vite + React client
The frontend can run in local two-player mode without requiring the backend:
cd frontend
npm install
npm run devThis will start the Vite development server (usually on http://localhost:5173). Both players can play from the same device/browser.
For real-time multiplayer with separate devices:
Start the backend:
cd backend
npm install
npm run devThis starts the Express + Socket.IO server on port 4000.
Start the frontend:
cd frontend
npm install
npm run devTo build the frontend for production:
cd frontend
npm install
npm run build
npm run previewThis repository is prepared to deploy the static frontend to Vercel and includes a simple serverless health endpoint at /api/health.
Key points:
- The frontend (Vite) is built from the
frontend/folder. Vercel will runnpm run buildinfrontendand publish the output. - A minimal serverless endpoint is available at
/api/health(seeapi/health.js). - The current backend (
backend/index.js) runs an Express + Socket.IO server which requires a long-lived WebSocket server. Vercel's serverless functions are not suitable for hosting a Socket.IO server (they do not support long-lived WebSocket servers reliably).
Recommended options for real-time backend:
- Deploy the existing Express + Socket.IO server to a platform that supports long-lived sockets (Render, Fly.io, a VPS, Railway). Then point the frontend to that server's URL.
- Replace socket-based realtime with a serverless-friendly realtime product (Pusher, Supabase Realtime, Ably) and update frontend to use that client.
How to deploy the frontend to Vercel (brief):
- Sign in to Vercel and import the repository.
- In the project settings, set the Root Directory to the repository root. The included
vercel.jsonroutes static files fromfrontendand provides/apiendpoints. - Ensure the Build Command is
npm run build --prefix frontendand the Output Directory isfrontend/distif Vercel asks.
If you want, I can:
- Add an example of switching the frontend to use an externally hosted Socket.IO server.
- Help create a small deployable backend on Render or Railway and wire it to the frontend.
To build the frontend locally (what Vercel will run under the hood):
npm --prefix frontend install
npm --prefix frontend run build- Added
vercel.jsonto configure Vercel's builds and routes. - Added
api/health.jsas a tiny serverless health endpoint. - Documented Socket.IO hosting recommendations.