Complete guide to setting up the Rock Spotter platform for development or production.
git clone https://github.com/jmenichole/Rock-Spotter.git
cd Rock-Spotter
cd backend
npm install
This will install:
Create a .env file in the backend directory:
cp .env.example .env
Edit .env with your configuration:
# Server Configuration
PORT=3000
NODE_ENV=development
# Database
MONGODB_URI=mongodb://localhost:27017/rock-spotter
# JWT Secret (IMPORTANT: Change this in production!)
JWT_SECRET=your-super-secret-jwt-key-change-this
# File Upload
UPLOAD_PATH=./uploads
MAX_FILE_SIZE=5242880
Important Security Notes:
.env to version control (already in .gitignore)brew install mongodb-communitysudo apt-get install mongodb# macOS/Linux
mongod --dbpath /path/to/data/directory
# Or as a service
brew services start mongodb-community # macOS
sudo systemctl start mongod # Linux
mongo
> show dbs
MONGODB_URI in .env:
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/rock-spotter?retryWrites=true&w=majority
Development mode (with auto-reload):
npm run dev
Production mode:
npm start
The server will start on http://localhost:3000 (or your configured PORT).
You should see:
MongoDB connected successfully
Rock Spotter API server running on port 3000
Test the health check endpoint:
curl http://localhost:3000/api/health
Expected response:
{
"status": "ok",
"message": "Rock Spotter API is running!"
}
curl -X POST http://localhost:3000/api/users/register \
-H "Content-Type: application/json" \
-d '{
"username": "testuser",
"email": "test@example.com",
"password": "password123"
}'
curl -X POST http://localhost:3000/api/users/login \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123"
}'
Save the token from the response for authenticated requests.
curl -X POST http://localhost:3000/api/rocks \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-d '{
"title": "Test Rock",
"description": "A test rock",
"photo": "https://example.com/rock.jpg",
"location": {
"type": "Point",
"coordinates": [-122.4194, 37.7749],
"address": "San Francisco, CA"
},
"rockType": "igneous",
"tags": ["test"],
"isPublic": true
}'
base_url: http://localhost:3000/apitoken: (will be set after login)cd backend
npm run dev
This uses nodemon to auto-reload on file changes.
git checkout -b feature/your-feature-name
Make your changes to the code
Test your changes
git add .
git commit -m "Add your feature"
git push origin feature/your-feature-name
backend/
├── src/
│ ├── controllers/ # Business logic
│ │ ├── userController.js
│ │ ├── rockController.js
│ │ ├── huntController.js
│ │ └── achievementController.js
│ ├── models/ # Database models
│ │ ├── User.js
│ │ ├── Rock.js
│ │ ├── Hunt.js
│ │ └── Achievement.js
│ ├── routes/ # API routes
│ │ ├── userRoutes.js
│ │ ├── rockRoutes.js
│ │ ├── huntRoutes.js
│ │ └── achievementRoutes.js
│ ├── middleware/ # Custom middleware
│ │ └── auth.js
│ └── server.js # Main application file
├── .env.example # Environment template
├── .gitignore
├── package.json
└── README.md
To test the application, you might want to seed some sample data:
// Create a seed script at backend/scripts/seed.js
const mongoose = require('mongoose');
const User = require('../src/models/User');
const Rock = require('../src/models/Rock');
const Achievement = require('../src/models/Achievement');
require('dotenv').config();
async function seed() {
await mongoose.connect(process.env.MONGODB_URI);
// Clear existing data
await User.deleteMany({});
await Rock.deleteMany({});
await Achievement.deleteMany({});
// Create sample users
const users = await User.create([
{
username: 'rockfan',
email: 'rockfan@example.com',
password: 'password123',
bio: 'Love collecting rocks!'
},
// Add more users
]);
// Create sample achievements
const achievements = await Achievement.create([
{
name: 'First Rock',
description: 'Share your first rock photo',
icon: '🪨',
type: 'rocks',
criteria: { type: 'count', target: 1 },
rarity: 'common'
},
// Add more achievements
]);
console.log('Database seeded!');
process.exit(0);
}
seed();
Run with:
node scripts/seed.js
Error: MongoNetworkError: failed to connect to server
Solutions:
mongod --version.envError: EADDRINUSE: address already in use :::3000
Solutions:
.env# Find process
lsof -i :3000
# Kill process
kill -9 <PID>
Error: Invalid authentication token
Solutions:
Error: Cannot find module 'express'
Solution:
cd backend
rm -rf node_modules package-lock.json
npm install
# Install Heroku CLI
brew install heroku/brew/heroku
# Login and create app
heroku login
heroku create rock-spotter-api
# Set environment variables
heroku config:set NODE_ENV=production
heroku config:set MONGODB_URI=your_production_mongodb_uri
heroku config:set JWT_SECRET=your_production_secret
# Deploy
git push heroku main
# Check logs
heroku logs --tail
Use Elastic Beanstalk or EC2 with similar setup to DigitalOcean.
For production, use PM2 to keep the app running:
npm install -g pm2
# Start app
pm2 start src/server.js --name rock-spotter
# Auto-restart on reboot
pm2 startup
pm2 save
# Monitor
pm2 monit
# View logs
pm2 logs rock-spotter
For issues or questions:
/docsHappy rock spotting! 🪨🔍