This guide shows you how to set up the backend API for development.
The backend API provides:
cd backend
npm install
Create backend/.env
file (if not done in database setup):
PORT=3001
NODE_ENV=development
# Firebase credentials (from database setup)
FIREBASE_PROJECT_ID=your_project_id
FIREBASE_PRIVATE_KEY_ID=your_private_key_id
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxxxx@your_project.iam.gserviceaccount.com
FIREBASE_CLIENT_ID=your_client_id
npm start
You should see:
Server running on port 3001
Environment: development
Health check: http://localhost:3001/health
API Docs: http://localhost:3001/api-docs
Open your browser and visit:
You should see the API is running!
npm start # Start the server
npm run dev # Start with auto-reload (nodemon)
npm test # Run tests
npm run test:coverage # Run tests with coverage
npm run lint # Check code style
npm run lint:fix # Fix code style issues
backend/
├── src/
│ ├── server.js # Main server file
│ ├── config/ # Configuration files
│ ├── middleware/ # Authentication, error handling
│ ├── routes/ # API endpoints
│ ├── services/ # Business logic
│ ├── models/ # Database schemas
│ └── tests/ # Test files
├── package.json # Dependencies
└── .env # Environment variables
The API provides these endpoints:
/api/auth
- Login, signup, token verification/api/users
- User profiles and preferences/api/hikes
- Hike logging and GPS tracking/api/goals
- Goals and achievements/api/friends
- Friend system/api/feed
- Activity feed/api/gear
- Gear management/api/discover
- Popular locations/api/planned-hikes
- Future hike planning/api/public
- Public API (no auth required)For detailed documentation:
src/routes/
src/services/
src/server.js
src/tests/
# Test health endpoint
curl http://localhost:3001/health
# Test public stats (no auth)
curl http://localhost:3001/api/public/stats
# Test with authentication
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:3001/api/users/profile
Problem: Port 3001 already in use
# Solution: Kill the process
npx kill-port 3001
Problem: Firebase connection error
.env
file has correct Firebase credentialsProblem: “Cannot find module” errors
# Solution: Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
Problem: CORS errors from frontend
src/middleware/index.js
allows http://localhost:3000
Run tests to verify everything works:
# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Run specific test file
npm test -- auth.test.js
The frontend will connect to http://localhost:3001