Skip to main content

Backend Setup

This guide will help you set up the ThePlugg backend API locally.

Prerequisites

  • Node.js 18 or higher
  • PostgreSQL database
  • npm or yarn

Installation

  1. Clone the repository (if not already cloned)
cd ThePlugg-backend
  1. Install dependencies
npm install
  1. Set up environment variables

Create a .env file in the root directory:

# Database
DB_URL="postgresql://user:password@host:port/database"

# Server
PORT=3000
NODE_ENV=development

# JWT
JWT_SECRET=your-secret-key

# AWS S3 (for file storage)
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=your-region
AWS_S3_BUCKET=your-bucket-name

# BulkSMS
BULKSMS_TOKEN_ID=your-token-id
BULKSMS_TOKEN_SECRET=your-token-secret
BULKSMS_BASIC_AUTH=Authorization: Basic base64encoded

# OneSignal
ONESIGNAL_APP_ID=your-app-id
ONESIGNAL_API_KEY=your-api-key

# CORS
CORS_ALLOWED_ORIGINS=http://localhost:3001,http://localhost:4000

# API Key (for admin routes)
API_KEY=your-admin-api-key
  1. Set up the database
# Generate Prisma client
npm run prisma:generate

# Run migrations
npm run prisma:migrate

# (Optional) Seed the database
npm run prisma:seed
  1. Start the development server
npm run dev

The API will be available at http://localhost:3000

Verify Installation

Check the health endpoint:

curl http://localhost:3000/health

You should receive:

{
"status": "ok",
"timestamp": "2024-01-01T00:00:00.000Z"
}

Next Steps