This guide covers deploying the Rock Spotter backend API to various cloud platforms and using Docker.
All deployment platforms require these environment variables:
| Variable | Description | Example |
|---|---|---|
NODE_ENV |
Environment mode | production |
PORT |
Server port (usually auto-set) | 3000 |
MONGODB_URI |
MongoDB connection string | mongodb+srv://user:pass@cluster.mongodb.net/rock-spotter |
JWT_SECRET |
Secret key for JWT tokens | your-random-secret-key-here |
Option 1: MongoDB Atlas (Recommended)
0.0.0.0/0 for all IPs)<password> with your database passwordmyFirstDatabase with rock-spotterOption 2: Local MongoDB
mongodb://localhost:27017/rock-spotter
The project includes a docker-compose.yml that sets up both the API and MongoDB.
git clone https://github.com/jmenichole/Rock-Spotter.git
cd Rock-Spotter
.env file in the root directory:
JWT_SECRET=your-random-secret-key-here
docker-compose up -d
curl http://localhost:3000/api/health
docker-compose logs -f backend
docker-compose down
cd backend
docker build -t rock-spotter-api .
docker run -d \
-p 3000:3000 \
-e MONGODB_URI="your-mongodb-uri" \
-e JWT_SECRET="your-secret-key" \
-e NODE_ENV=production \
--name rock-spotter \
rock-spotter-api
docker ps
docker logs rock-spotter
Render offers free hosting for web services and is great for hobby projects.
Fork/Clone the repository to your GitHub account
Create a MongoDB Atlas database (free tier available)
render.yaml and configure services automaticallyMONGODB_URI with your MongoDB Atlas connection stringJWT_SECRET will be auto-generatedhttps://rock-spotter-api.onrender.comrock-spotter-apiNodemaincd backend && npm installcd backend && npm startNODE_ENV = productionMONGODB_URI = your-mongodb-atlas-uriJWT_SECRET = your-random-secret-keyRailway offers $5 free credit per month and excellent developer experience.
npm install -g railway
railway.json configurationMONGODB_URIJWT_SECRETNODE_ENV and PORT are auto-set# Login
railway login
# Initialize project
cd Rock-Spotter
railway init
# Add MongoDB
railway add
# Set variables
railway variables set JWT_SECRET=your-secret-key
# Deploy
railway up
Heroku is a classic PaaS with free tier (limited).
npm install -g heroku
heroku login
cd Rock-Spotter
heroku create rock-spotter-api
heroku addons:create mongolab:sandbox
heroku config:set MONGODB_URI=”your-mongodb-atlas-uri”
5. **Set environment variables:**
```bash
heroku config:set JWT_SECRET="your-random-secret-key"
heroku config:set NODE_ENV=production
git push heroku main
heroku open
heroku logs --tail
The project includes a Procfile for Heroku:
web: cd backend && npm start
DigitalOcean offers $200 free credit for 60 days.
Create account at DigitalOcean
mainrock-spotter-apibackendnpm installnpm start3000NODE_ENV=production
MONGODB_URI=your-mongodb-uri
JWT_SECRET=your-secret-key
AWS offers 12 months free tier for new accounts.
pip install awsebcli
cd Rock-Spotter
eb init -p node.js rock-spotter-api --region us-west-2
eb create rock-spotter-env
eb setenv NODE_ENV=production \
MONGODB_URI="your-mongodb-uri" \
JWT_SECRET="your-secret-key"
eb deploy
eb open
eb logs
Create .ebextensions/nodecommand.config:
option_settings:
aws:elasticbeanstalk:container:nodejs:
NodeCommand: "cd backend && npm start"
Note: These platforms are optimized for frontend apps and serverless functions. The Rock Spotter backend uses Express with persistent MongoDB connections, which works better on traditional hosting platforms (Render, Railway, Heroku).
If you want to deploy on Vercel/Netlify, you’ll need to refactor the backend into serverless functions.
After deploying to any platform:
# Health check
curl https://your-app-url.com/api/health
# Should return:
# {"status":"ok","message":"Rock Spotter API is running!"}
curl -X POST https://your-app-url.com/api/users/register \
-H "Content-Type: application/json" \
-d '{
"username": "testuser",
"email": "test@example.com",
"password": "password123"
}'
curl -X POST https://your-app-url.com/api/users/login \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123"
}'
Check your platform logs to ensure MongoDB connection is successful:
MongoDB connected successfully
Rock Spotter API server running on port 3000
If you have a frontend, update CORS settings in backend/src/server.js:
app.use(cors({
origin: ['https://your-frontend-url.com'],
credentials: true
}));
Generate a secure secret:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
Most platforms allow adding custom domains:
Update your README with:
Solutions:
0.0.0.0/0Solution: Most platforms auto-set PORT. In server.js:
const PORT = process.env.PORT || 3000;
Solution: Ensure JWT_SECRET is set and matches on all instances
Solutions:
package.jsonSolutions:
Most platforms support automatic deployment from Git:
git add .
git commit -m "Update API"
git push origin main
# Render: Auto-deploys on git push
# Railway: railway up
# Heroku: git push heroku main
# DigitalOcean: Auto-deploys on git push
heroku ps:scale web=2| Platform | Free Tier | Paid Tier Starts At |
|---|---|---|
| Render | 750 hrs/month | $7/month |
| Railway | $5 credit/month | $0.000231/GB-hour |
| Heroku | 1000 hrs/month | $7/month |
| DigitalOcean | $200 credit (60 days) | $5/month |
| AWS EB | 12 months free | Varies |
| MongoDB Atlas | 512MB free | $9/month |
npm audit)helmet middleware)express-validator)For deployment issues:
After successful deployment:
Congratulations on deploying Rock Spotter! 🪨🚀
Your API is now live and ready to serve rock enthusiasts worldwide!