Overview
Mokepon is designed to be deployed on Heroku, a cloud platform that supports Node.js applications. The deployment process is straightforward and leverages Heroku’s automatic deployment from Git.Heroku Deployment
Prerequisites
Before deploying, ensure you have:- A Heroku account (sign up here)
- Heroku CLI installed (installation guide)
- Git installed and repository initialized
- All changes committed to your Git repository
Deployment Process
Login to Heroku
Authenticate with Heroku via the CLI:This will open a browser window for authentication.
Create a Heroku app
Create a new Heroku application:Or let Heroku generate a random name:
The live Mokepon game uses the URL:
https://mokepon-ed1d40aff3a6.herokuapp.com/Configure environment variables
Set the production environment variable:The
PORT variable is automatically set by Heroku and doesn’t need manual configuration.Deploy to Heroku
Push your code to Heroku:Or if your default branch is Heroku will automatically:
master:- Detect the Node.js application
- Install dependencies from
package.json - Run the start script defined in the
Procfile
Procfile Configuration
TheProcfile tells Heroku how to run your application:
Procfile
- Defines a
webprocess type (required for web applications) - Executes
node index.jsto start the Express server - Automatically binds to Heroku’s dynamically assigned
PORT
Heroku uses the
Procfile to determine which command to run. The web process type is special because it’s the only process that receives HTTP traffic.Environment Variables
Required Variables
| Variable | Set By | Description |
|---|---|---|
PORT | Heroku | Automatically assigned port (DO NOT override) |
NODE_ENV | You | Set to "production" for production behavior |
Setting Environment Variables
Using Heroku CLI:- Navigate to your app in the Heroku dashboard
- Go to Settings tab
- Click Reveal Config Vars
- Add or edit variables
PORT Environment Variable
The server dynamically uses Heroku’s PORT:index.js
Production Configuration
Environment Detection
The application behaves differently in production:index.js
.env files are only used during local development, not in production where environment variables come from Heroku’s config.
CORS Configuration
CORS is restricted in production for security:index.js
In production, update the CORS origin to match your Heroku app’s URL. Replace
mokepon-ed1d40aff3a6.herokuapp.com with your actual domain.Security Middleware
The application uses Helmet to set secure HTTP headers:index.js
- Restricts resource loading to same origin by default
- Allows external scripts from CDN (jsdelivr)
- Permits Google Fonts for styling
- Prevents XSS attacks and unauthorized resource loading
Response Compression
Compression middleware reduces payload size:index.js
Error Handling
Production Error Responses
Error handling differs between development and production:index.js
- Stack traces are hidden from API responses
- Only the error message is sent to clients
- Full errors are logged server-side for debugging
- Full stack traces are included in responses
- Makes debugging easier during development
Node.js Version
The application specifies the Node.js version inpackage.json:
package.json
>=14.0.0 requirement ensures ES module support.
Deployment Checklist
Before deploying to production, verify:Code quality
- All features tested locally
- No console errors in browser
- All API endpoints functioning correctly
- Game mechanics working as expected
Configuration
-
package.jsonhas correct dependencies -
Procfilepoints to correct entry file - Environment variables configured
- CORS origin updated to production URL
Security
- No sensitive data in repository
-
.gitignoreincludes.env - Helmet CSP properly configured
- CORS restricted in production
Monitoring and Logs
Viewing Logs
View real-time logs from your Heroku app:Application Metrics
Monitor your application through the Heroku dashboard:- Navigate to your app
- Click on the Metrics tab
- View response times, throughput, memory usage, etc.
Troubleshooting
Application Crashes
If your app crashes:Port Binding Issues
Ensure your application usesprocess.env.PORT:
Build Failures
If the build fails:- Check that all dependencies are in
package.json - Ensure Node.js version compatibility
- Verify the
Procfileis correct - Review build logs for specific errors
CORS Errors
If you see CORS errors in production:- Verify the CORS origin matches your Heroku URL
- Check that
NODE_ENVis set to"production" - Ensure allowed methods include those your client uses
Continuous Deployment
For automatic deployments from GitHub:Connect GitHub
In the Heroku dashboard:
- Go to your app’s Deploy tab
- Select GitHub as deployment method
- Connect your GitHub account and repository
Custom Domain (Optional)
To use a custom domain:Next Steps
- Review project structure to understand the codebase
- Check setup guide for local development
- Monitor your application logs and metrics regularly
- Consider implementing additional features or optimizations