Here’s an updated README.md file that includes the use of express.static to serve static files, along with other relevant details about the project:
This repository contains the Node.js server for the game Holes. It facilitates real-time communication, serves static files for the client, and manages game data with a custom map generation system.
- Real-time Communication: Socket.io is used to enable real-time events between the client and server.
- Static File Serving: Serves the static files for the client from the
../Holes_clientdirectory. - Dynamic Map Generation: Includes noise-based map generation for the game world.
- Player Management: Tracks and updates player positions and actions in real-time.
- Node.js: Ensure you have Node.js installed on your system.
- npm: Installed alongside Node.js.
-
Clone the Repository:
git clone https://github.com/your-username/holes_server.git cd holes_server -
Install Dependencies:
npm install
-
Directory Setup:
Ensure the
Holes_clientdirectory exists as a sibling to this server directory. For example:../ ├── Holes_client/ # Client-side files └── Holes_server/ # This server directory -
Start the Server:
node server.js
The server is configured to serve static files from the ../Holes_client directory. This allows the client-side game to be hosted directly from this Node.js server.
Relevant code snippet:
// Serve static files
app.use(express.static('../Holes_client'));Access the client files in your browser by navigating to http://localhost:3000.
| Event Name | Payload | Description |
|---|---|---|
connection |
socket |
Triggered when a new client connects |
new_player |
{id, position, ...} |
Adds a new player to the game |
update_pos |
{id, position} |
Updates the position of a player |
update_node |
{index, value} |
Updates the map node |
disconnect |
Triggered when a client disconnects |
The server includes a noise-based map generation system. Each map is dynamically created using the simplex-noise library. Features include:
- Noise-based terrain generation.
- Room creation with boundary conditions.
- Port: The server listens on port
3000by default. This can be modified in theserver.jsfile.
-
Use nodemon for automatic server reloads during development:
npm install -g nodemon nodemon server.js
SERVER_LOGO
SERVER_NAME
If you encounter CORS errors, ensure that the frontend and backend are configured properly. The server has been configured to allow requests from http://127.0.0.1:5500.
docker pull polypikzel/holesgame
