Prerequisites
Before you begin, ensure you have the following installed on your system:- Node.js: Version 14.0.0 or higher
- npm: Comes bundled with Node.js (or use yarn/pnpm as alternatives)
- Git: For cloning the repository
The project uses ES modules (
"type": "module" in package.json), so make sure your Node.js version supports this feature.Installation
Install dependencies
Install all required npm packages:This will install the following production dependencies:
express(^4.21.2) - Web framework for Node.jscors(^2.8.5) - Enable Cross-Origin Resource Sharingcompression(^1.8.0) - Response compression middlewarehelmet(^8.1.0) - Security headers middleware
dotenv(^16.4.7) - Environment variable management
Environment Configuration
Development Mode
In development mode, the application loads environment variables from a.env file using dotenv:
.env file in the root directory (optional for local development):
.env
Environment Variables
| Variable | Description | Default | Required |
|---|---|---|---|
PORT | Server port number | 3000 | No |
NODE_ENV | Environment mode (development or production) | development | No |
In development mode, CORS is configured to allow all origins (
"*"). This makes it easier to test the game from different devices on your local network.Development vs Production
The application behaves differently based on theNODE_ENV environment variable:
Development Mode
- Loads environment variables from
.envfile - CORS allows all origins (
"*") - Full error stack traces are sent in API responses
- Easier debugging and testing
Production Mode
- Environment variables from hosting platform (Heroku)
- CORS restricted to production domain:
https://mokepon-ed1d40aff3a6.herokuapp.com - Error stack traces are hidden from API responses
- Security headers enforced via Helmet
- Response compression enabled
Available Scripts
The following npm scripts are defined inpackage.json:
npm start: Starts the Express server usingindex.jsnpm test: Placeholder for future test implementation
Troubleshooting
Port Already in Use
If port 3000 is already in use, you can specify a different port:.env file:
Module Import Errors
If you encounter ES module import errors, ensure:- You’re using Node.js 14.0.0 or higher
- The
package.jsoncontains"type": "module" - All imports use the
.jsextension
Canvas Rendering Issues
If the game map doesn’t render properly:- Check browser console for errors
- Ensure the map image exists at
/public/assets/images/mokemap.png - Clear your browser cache and reload
Next Steps
Now that you have the development environment set up:- Learn about the project structure
- Explore the deployment process
- Start making changes and testing new features