This guide explains how to set up and use the backend code for the Hikemeet project. It covers cloning the repository, installing dependencies, configuring MongoDB and Firebase for both production and staging environments, and managing environment variables.
The Hikemeet backend is a robust application built with Node.js and Express, designed to support a social platform for hikers. It handles user authentication, trip management, group interactions, notifications, and image uploads. The architecture leverages a MongoDB database for data persistence and Firebase for authentication and other services. The application is containerized using Docker and deployed using Kubernetes, ensuring scalability and easy management across different environments.
- ποΈ Runtime & Framework: Node.js, Express.js
- π οΈ Language & Tooling: TypeScript, ts-node, nodemon, ESLint, Prettier
- πΎ Database & ORM: MongoDB Atlas, Mongoose
- π Authentication & Notifications: Firebase Admin SDK, Expo Server SDK
- πΌοΈ File & Media Handling: Cloudinary, Multer
- β° Background Jobs & Scheduling: node-cron
- π Logging & Monitoring: Winston, Morgan
- βοΈ Email Service: Nodemailer (Gmail SMTP)
- π Security & Configuration: dotenv, JSON Web Tokens
- π³ Containerization & Orchestration: Docker, Kubernetes (Deployments, Services, Ingress)
- π CI/CD Pipelines: GitHub Actions (build, test, deploy)
- Node.js (v16.x or higher)
- npm
- MongoDB (one for production, one for staging)
- Firebase project (one for production, one for staging)
- Git
git clone <repository_url>
cd <repository_name>npm installCreate two MongoDB databases:
Update the .env file with these connection strings.
Set up two Firebase projects:
* Go to the [Firebase Console](https://console.firebase.google.com).
* Create a new project for production.
* Add an app (Web/Android/iOS as required).
* Obtain the service account key JSON file and download it.
* Repeat the same steps to create a staging project.
Update the .env file to include Firebase configuration for both projects.
NODE_ENV=local # Use 'local', 'stage', or 'prod'PORT=
# MongoDB
MONGO_URI=
# Firebase
FIREBASE_TYPE=
FIREBASE_PROJECT_ID=
FIREBASE_PRIVATE_KEY_ID=
FIREBASE_PRIVATE_KEY=
FIREBASE_CLIENT_EMAIL=
FIREBASE_CLIENT_ID=
FIREBASE_AUTH_URI=
FIREBASE_TOKEN_URI=
FIREBASE_AUTH_PROVIDER_CERT_URL=
FIREBASE_CLIENT_CERT_URL=
# Cloudinary (Optional, if using image upload)
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
# Mailer (Optional, if using email services)
MAILER_EMAIL=
MAILER_PASSWORD=Update the NODE_ENV value in .env to either local, stage, or prod.
NODE_ENV=prodTo run the server in different environments:
- Local Environment:
npm run dev
- Production Environment:
npm start
The Hikemeet backend is designed for deployment in containerized environments, primarily using Docker and Kubernetes.
-
Docker
Uses aDockerfile(Node.js 20) to:- Install dependencies
- Build the TypeScript code
- Expose port
3000 - Run the app with
npm start
-
Kubernetes
Includes the following manifests:hikemeet.yaml- Deployment: 3 replicas of
wooozai/hikemeet:latest - Env via Secret
hikemeet-secrets - ClusterIP Service on port 80 β 3000
- Deployment: 3 replicas of
hikemeet-ingress.yaml- NGINX Ingress routing HTTP/HTTPS to
hikemeet-service - SSL redirect, host
hikemeet.com, TLS secret
- NGINX Ingress routing HTTP/HTTPS to
hikemeet-secrets.example.yaml- Example Secret for sensitive env vars (MongoDB URI, Firebase keys, Cloudinary, mailer)
mongo-service.yaml- ExternalName Service pointing to your MongoDB Atlas cluster
-
Deployment Steps
- Create/update your Kubernetes Secrets (or
.env.*files). - Apply manifests:
kubectl apply -f kubernetes/hikemeet-secrets.example.yaml kubectl apply -f kubernetes/hikemeet.yaml kubectl apply -f kubernetes/mongo-service.yaml kubectl apply -f kubernetes/hikemeet-ingress.yaml
- Ensure youβre using the correct environment (
.env.prodfor production,.env.stagefor staging).
- Create/update your Kubernetes Secrets (or
- MongoDB Connection Issues:
- Ensure the correct connection string is provided.
- Verify network access rules in MongoDB Atlas.
- Firebase Authentication Issues:
- Ensure the Firebase service account key is correctly configured.
- Verify project permissions in the Firebase Console.
Add badges from somewhere like: shields.io