npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tjoc/trivia-api

v1.0.1

Published

Trivia game API backend with Express and TypeScript

Readme

Trivia API Backend

A robust Express.js API backend for the TJOC Trivia application, built with TypeScript and following enterprise-grade patterns.

🚀 Quick Start

Prerequisites

  • Node.js 18+
  • PostgreSQL 14+
  • Redis 6+
  • pnpm package manager

Installation

  1. Install dependencies:
pnpm install
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your configuration
  1. Start the development server:
pnpm dev

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

📁 Project Structure

src/
├── config/          # Configuration files
│   ├── index.ts      # Environment validation
│   └── database.ts   # Database connections
├── middleware/       # Express middleware
│   ├── errorHandler.ts
│   ├── notFoundHandler.ts
│   ├── requestLogger.ts
│   └── validateRequest.ts
├── routes/          # API route handlers
├── services/        # Business logic
├── models/          # Database models
├── utils/           # Utility functions
│   └── logger.ts    # Logging utility
├── types/           # TypeScript type definitions
├── scripts/         # Database and utility scripts
├── app.ts           # Express app configuration
├── server.ts        # Server startup
└── index.ts         # Entry point

🔧 Available Scripts

  • pnpm dev - Start development server with hot reload
  • pnpm build - Build for production
  • pnpm start - Start production server
  • pnpm test - Run tests
  • pnpm test:watch - Run tests in watch mode
  • pnpm lint - Run ESLint
  • pnpm lint:fix - Fix ESLint issues
  • pnpm format - Format code with Prettier

🌐 API Endpoints

Health Check

  • GET /health - Server health status
  • GET /api/v1 - API welcome message

Authentication (Coming Soon)

  • POST /api/v1/auth/register - User registration
  • POST /api/v1/auth/login - User login
  • POST /api/v1/auth/refresh - Refresh token
  • POST /api/v1/auth/logout - User logout

Games (Coming Soon)

  • GET /api/v1/games - List available games
  • POST /api/v1/games/free - Start free game
  • POST /api/v1/games/ranked - Start ranked game
  • POST /api/v1/games/special - Start special game

🔒 Security Features

  • Helmet.js - Security headers
  • CORS - Cross-origin resource sharing
  • Rate Limiting - Request throttling
  • Input Validation - Zod schema validation
  • JWT Authentication - Secure token-based auth
  • Password Hashing - bcrypt encryption

📊 Monitoring & Logging

  • Morgan - HTTP request logging
  • Custom Logger - Structured application logging
  • Error Handling - Centralized error management
  • Health Checks - System status monitoring

🗄️ Database

  • PostgreSQL - Primary database
  • Redis - Caching and sessions
  • Connection Pooling - Optimized database connections
  • Transactions - ACID compliance

🔧 Configuration

All configuration is managed through environment variables. See .env.example for required variables.

Key Environment Variables

  • NODE_ENV - Environment (development/production/test)
  • PORT - Server port (default: 3001)
  • DATABASE_URL - PostgreSQL connection string
  • REDIS_HOST - Redis server host
  • JWT_SECRET - JWT signing secret
  • STRIPE_SECRET_KEY - Stripe payment processing

🧪 Testing

The project uses Jest for testing with TypeScript support:

# Run all tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Run tests with coverage
pnpm test:coverage

📈 Development Status

✅ Phase 1: Project Setup (Completed)

  • [x] Express TypeScript project structure
  • [x] Core dependencies and configuration
  • [x] Middleware setup (CORS, logging, error handling)
  • [x] Database connections (PostgreSQL, Redis)
  • [x] Environment configuration
  • [x] Development server setup

🔄 Phase 2: Authentication & User Management (Next)

  • [ ] User registration and login
  • [ ] JWT token management
  • [ ] Password reset functionality
  • [ ] User profile management
  • [ ] Role-based access control

📋 Upcoming Phases

  • Phase 3: Game Management
  • Phase 4: Leaderboards & Scoring
  • Phase 5: Payment & Subscription
  • Phase 6: Referral System
  • Phase 7: Admin Dashboard API
  • Phase 8: Real-time Features
  • Phase 9: Testing & Documentation

🤝 Contributing

  1. Follow the existing code style and patterns
  2. Write tests for new features
  3. Update documentation as needed
  4. Use conventional commit messages

📄 License

This project is part of the TJOC monorepo.