Chess BackEnd is the backend implementation for a chess game application. This repository features a RESTful API built with Node.js and Express, while Socket.IO facilitates real-time communication between players. The chess game logic is managed by the chessGame.js library, and EJS is used for server-side templating. This implementation provides a solid foundation for creating interactive and real-time chess experiences.
- Node.js
- Express
- Socket.IO
- chess.js
- EJS
- nodemon (for development)
chess.js: "^1.0.0"ejs: "^3.1.10"express: "^4.21.2"nodemon: "^3.1.9"socket.io: "^4.8.1"
-
Real-time Game Play:
Leverages Socket.IO for live communication between clients, enabling real-time chess moves and game status updates. -
Robust Game Logic:
Utilizes chess.js to handle game rules, move validation, check, checkmate, and stalemate conditions. -
Server-Side Rendering:
EJS is used to dynamically render HTML views, simplifying the integration of game logic with the user interface. -
Developer Friendly:
Integrated with nodemon for automatic server restarts during development, speeding up the feedback loop.
Follow these steps to set up the project locally:
-
Run the Setup Script
Download and execute the provided setup script to clone the repository and install dependencies automatically:
curl -fsSL https://raw.githubusercontent.com/ayush-jadaun/chessBackEnd/main/setup.sh | bashThis will take care of cloning the repository, installing dependencies, and starting the server for you.
-
Manual Setup (Optional)
If you prefer manual setup, follow these commands:
git clone https://github.com/ayush-jadaun/chessBackEnd.git cd chessBackEnd npm install npm run startThe server should now be running. By default, it listens on port 3000 (you can change this in your configuration).
2.1 If you downloaded setup.sh manually, make it executable first:
chmod +x setup.sh
./setup.sh
chessBackEnd/
├── node_modules/
├── public/
│ ├── css/
│ └── js/chessGame.js
│
├── views/
│ └── index.ejs
├── package.json
├── package-lock.json
└── app.js
- public/: Contains static assets like CSS, JavaScript, and image files.
- views/: Contains EJS templates for the application views.
- app.js: The main entry point of the application where the Express server, Socket.IO, and chess.js integrations are configured.
After starting the server, open your browser and navigate to:
http://localhost:3000
You will be presented with the landing page. From here, you can start a new game, or continue an existing one. All game moves are processed by the backend, with real-time updates delivered to connected clients via sockets.
-
Changing the Port:
You can change the server port by modifying the code inapp.jsor setting an environment variable (e.g.,PORT=5000). -
Templating:
Update or add new EJS templates in theviews/directory to customize the user interface. -
Static Assets:
Place your CSS, JavaScript, or images in thepublic/directory and reference them in your EJS files.
-
Socket.IO Issues:
Ensure that your clients are able to reach the server and that firewalls or proxies are not blocking the WebSocket connections. -
Dependency Conflicts:
If you encounter issues with dependencies, try deleting thenode_modulesfolder and runningnpm installagain. -
Restarting the Server:
When making changes during development, nodemon will automatically restart the server. If you encounter issues related to caching, consider manually restarting the server.
Contributions are welcome! To contribute:
- Fork this repository.
- Create a feature branch (
git checkout -b feature/YourFeature). - Commit your changes (
git commit -am 'Add new feature'). - Push your changes (
git push origin feature/YourFeature). - Open a pull request detailing your changes.
Happy coding!