Harshit Metrics
Guides

Self-Hosting

Deploy your own instance of Harshit Metrics.

Requirements

  • Node.js 18+
  • MongoDB 6+ (local or Atlas)
  • Clerk account (for authentication)

Environment variables

Create a .env.local file in apps/web/:

# MongoDB connection
MONGODB_URI=mongodb://127.0.0.1:27017
MONGODB_DB=metrics

# API key security pepper (change this!)
API_KEY_PEPPER=your-random-secret-pepper

# App URL
APP_BASE_URL=https://your-domain.com

# Clerk authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_...
CLERK_SECRET_KEY=sk_live_...

Local development

# Clone the repository
git clone https://github.com/harshitkumar9030/metrics.git
cd metrics

# Install dependencies
pnpm install

# Start MongoDB (if local)
mongod --dbpath ./data

# Run the development server
cd apps/web
pnpm dev

The app will be available at http://localhost:3000.

Production deployment

  1. Push to GitHub
  2. Import the repository in Vercel
  3. Set the root directory to apps/web
  4. Add all environment variables
  5. Deploy

Docker

FROM node:20-slim AS builder
WORKDIR /app
COPY . .
RUN npm install -g pnpm && pnpm install
RUN cd apps/web && pnpm build

FROM node:20-slim
WORKDIR /app
COPY --from=builder /app/apps/web/.next .next
COPY --from=builder /app/apps/web/package.json .
COPY --from=builder /app/node_modules node_modules
EXPOSE 3000
CMD ["pnpm", "start"]

MongoDB setup

Local MongoDB

Install and run MongoDB locally. The app creates indexes automatically on first use.

MongoDB Atlas

  1. Create a free cluster at mongodb.com/atlas
  2. Create a database user
  3. Whitelist your server's IP
  4. Copy the connection string to MONGODB_URI

SDK configuration for self-hosted

Point your SDK to your own instance:

const metrics = createMetricsClient("mtr_your_key", {
  endpoint: "https://your-domain.com/api/collect",
});

On this page