Skip to content

Running the Application

This guide covers how to run the 2KRIKA backend service in different modes.

Prerequisites

Before running the application, make sure you have:

  1. ✅ Installed all dependencies
  2. ✅ Configured environment variables
  3. ✅ Set up your databases (SQL, MongoDB, Redis)

Database Setup

Run Migrations

Apply database migrations to create the required tables:

pnpm dev:migrate

This runs Sequelize migrations from adapters/shared/sql/migrations/.

Seed the Database (Optional)

Load sample data for development:

pnpm dev:seed

This runs seed files from adapters/shared/sql/seeders/.

Development Mode

Start the development server with hot-reload:

pnpm dev

The server will start on http://localhost:3000 (or the port specified in your PORT environment variable).

Features in Development Mode

  • 🔄 Hot reload - Automatic restart on code changes
  • 📝 Detailed logging - Console output for all operations
  • 🐛 Error stack traces - Full error details for debugging
  • 📊 Query logging - SQL queries logged to console

Production Mode

Build the Application

Compile TypeScript to JavaScript:

pnpm build

Built files are output to web/dist/.

Start Production Server

NODE_ENV=production node web/dist/main.js

Testing

Run All Tests

pnpm test

Run Tests with Coverage

pnpm test:ci

This generates a coverage report.

Run Tests in Watch Mode

pnpm test

Code Quality

Linting

Check code for linting errors:

pnpm lint

Format Checking

Check code formatting:

pnpm format

Accessing the Application

API Endpoints

The API is available at:

http://localhost:3000/api

Swagger Documentation

Interactive API documentation is available at:

http://localhost:3000/docs/swagger-ui

Health Check

Check if the server is running:

curl http://localhost:3000/api/health

Common Issues

Port Already in Use

If port 3000 is already in use, either:

  1. Stop the process using port 3000
  2. Use a different port:
    PORT=3001 pnpm dev
    

Database Connection Errors

Verify your database connection strings:

echo $SQL_DATABASE_URL
echo $MONGODB_URI
echo $REDIS_URL

Make sure all database services are running:

# Check PostgreSQL
pg_isready

# Check MongoDB
mongo --eval "db.runCommand({ connectionStatus: 1 })"

# Check Redis
redis-cli ping

Migration Errors

If migrations fail, check: 1. Database URL is correct 2. Database server is running 3. User has proper permissions

Reset and rerun migrations:

pnpm dev:seed:undo:all
pnpm dev:migrate

Next Steps