Skip to content

WouterOnGithub/Backend-Web-Node.js

Repository files navigation

Borderlands 3 API (Node.js + Express + SQLite)

Complete REST API for Borderlands 3 equipment management with six entities (weapons, vault_hunters, shields, relics, grenades, classmods) including full CRUD operations, advanced validation, authentication, pagination, sorting, and search functionality.

Features

  • 6 CRUD entities: weapons, vault-hunters, shields, relics, grenades, classmods
  • Advanced validation: Regex patterns, logical validation, centralized middleware
  • Authentication: JWT-based auth system with protected endpoints
  • Search & pagination: Multi-field search with limit/offset
  • Sorting: Sort by any field with asc/desc order
  • Security: Helmet, CORS, input validation, SQL injection protection
  • Documentation: Complete HTML documentation at root endpoint

Requirements

  • Node.js ≥20.0.0
  • npm

Installation and Usage

# Clone repository
git clone <repository-url>
cd Backend-Web-Node.js

# Install dependencies
npm install

# Setup database
npx knex migrate:latest
npx knex seed:run

# Start development server
npm run dev

# Start production server
npm start

Environment Variables

Create a .env file in root directory based on .env.example:

PORT=3000
NODE_ENV=development
DATABASE_PATH=./data/db.sqlite3
JWT_SECRET=your-super-secret-jwt-key-change-in-production-please
JWT_EXPIRES_IN=24h
BCRYPT_ROUNDS=12

Important: Always set a secure JWT_SECRET in production!

API Endpoints

Authentication

  • POST /api/auth/login - Login and get JWT token
  • GET /api/auth/me - Get current user (requires auth)
  • POST /api/auth/logout - Logout and invalidate token (requires auth)

Equipment Management

  • GET /api/weapons - List weapons with pagination, search, and sorting
  • POST /api/weapons - Create weapon (requires auth)
  • GET /api/weapons/:id - Get weapon by ID
  • PUT /api/weapons/:id - Update weapon (requires auth)
  • DELETE /api/weapons/:id - Delete weapon (requires auth)

Similar endpoints available for:

  • /api/vault-hunters
  • /api/shields
  • /api/relics
  • /api/grenades
  • /api/classmods

Query Parameters

  • limit (1-100, default 25) - Results per page
  • offset (>=0, default 0) - Pagination offset
  • sort - Field to sort by (name, rarity, etc.)
  • order (asc/desc, default asc) - Sort direction
  • q - Search across multiple fields

Documentation

Visit http://localhost:3000 for complete API documentation with examples.

Default Users

  • Admin: username: admin, password: admin123
  • User: username: user, password: user123

Scripts

  • npm run dev - Start with nodemon for development
  • npm start - Start production server
  • npm run migrate - Run database migrations
  • npm run seed - Populate database with sample data

Project Structure

src/
├── server.js             # Server startup and environment validation
├── app.js               # Express app factory (middleware, routes, error handlers)
├── db/
│   └── knex.js           # Database configuration
├── middleware/
│   ├── auth.js          # Authentication middleware
│   └── validation.js    # Centralized validation
├── routes/
│   ├── index.js         # Routes export file
│   ├── auth.js          # Authentication routes
│   ├── weapons.js       # Weapon CRUD routes
│   ├── vaultHunters.js  # Vault Hunter CRUD routes
│   ├── shields.js       # Shield CRUD routes
│   ├── relics.js        # Relic CRUD routes
│   ├── grenades.js      # Grenade CRUD routes
│   └── classmods.js     # Class Mod CRUD routes
└── utils/
    ├── constants.js      # Application constants
    ├── crudHandler.js   # Reusable CRUD operations
    ├── envValidation.js # Environment validation
    ├── responseHelper.js # Standardized response helper
    └── tokenBlacklist.js # Token blacklist for logout

Security Features

  • JWT-based authentication with token invalidation
  • Token blacklist for logout functionality
  • Input validation and sanitization
  • SQL injection prevention
  • CORS protection
  • Security headers (Helmet)
  • Request size limiting (10MB)
  • Response compression
  • Rate limiting ready

Sources and References

This project was developed using the following resources:

Core Technologies

Security Best Practices

Educational Resources

Code Patterns Used

  • CRUD pattern implementation based on Express.js best practices
  • JWT authentication pattern from express-jwt documentation examples
  • Validation middleware pattern from express-validator examples
  • Database migration patterns from Knex.js documentation

License

MIT License - see LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors