A Node.js/Express API that extends the PokeAPI with custom trainer and user management functionality. Built with TypeScript, MySQL, and comprehensive authentication.
Before running this application, ensure you have the following installed:
- Node.js (v18 or higher)
- npm (v8 or higher)
- MySQL (v8.0 or higher)
-
Clone the repository:
git clone git@github.com:bobbybaxter/poke-api-extension.git cd poke-api-extension -
Install dependencies:
npm install
-
Environment Configuration: Create a
.envfile in the root directory with the following variables:# Database Configuration MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USERNAME=your_mysql_username MYSQL_PASSWORD=your_mysql_password MYSQL_DATABASE=poke_api_extension # JWT Configuration ACCESS_TOKEN_SECRET=your_secret_jwt_key_here ACCESS_TOKEN_TTL=15m REFRESH_TOKEN_TTL_DAYS=7 # Server Configuration PORT=3000
Important: Replace the placeholder values with your actual configuration:
- Use a strong, randomly generated string for
ACCESS_TOKEN_SECRET - Update MySQL credentials to match your local setup
- Use a strong, randomly generated string for
-
Create the database:
CREATE DATABASE poke_api_extension;
-
Database migration: The application uses TypeORM with
synchronize: true, so tables will be automatically created when you first run the application.
npm run devThis starts the server with hot-reload enabled using ts-node-dev. The server will restart automatically when you make changes.
# Build the TypeScript code
npm run build
# Start the production server
npm startThe application will be available at http://localhost:3000 (or the port specified in your .env file).
npm testThis runs the complete test suite with coverage reporting.
npm run test:watchRuns tests in watch mode, automatically re-running when files change.
npm run coverageOpens the detailed HTML coverage report in your default browser.
A public Postman workspace is available with a complete collection for testing all API endpoints:
🔗 Postman Workspace - PokeAPI Extension
- Join the workspace by clicking the link above
- Fork the collection to your own workspace to make requests
- Set up the environment:
- Select the "dev" environment
- Ensure
base_urlis set tohttp://localhost:3000
To test authenticated endpoints, follow this workflow:
-
Register a new account:
POST /register { "username": "testuser", "email": "test@example.com", "password": "securepassword123" }
-
Login to get access token:
POST /login { "identifier": "testuser", "password": "securepassword123" }
-
Set up authentication:
- Copy the
access_tokenfrom the login response - Paste it into the
{{bearer_token}}environment variable in the "dev" environment - All protected routes will now automatically use this token
- Copy the
-
Test protected endpoints:
- User management:
/user/:id - Trainer operations:
/trainerendpoints - The collection will automatically include the Bearer token in headers
- User management:
The Postman collection uses these environment variables:
base_url: Your API base URL (default:http://localhost:3000)bearer_token: JWT access token (set manually after login)
POST /register- Create a new user accountPOST /login- Authenticate and receive access tokensPOST /logout- Revoke refresh tokenPOST /refresh- Refresh access token using refresh token
GET /pokemon- List all pokemon from PokeAPIGET /pokemon/:idOrName- Get specific pokemon by ID or name
GET /user/:id- Get user informationPUT /user/:id- Update user informationDELETE /user/:id- Delete user account
GET /trainer- List all trainersGET /trainer/:id- Get specific trainerPOST /trainer- Create new trainerPUT /trainer/:id- Update trainer informationDELETE /trainer/:id- Delete trainer
Note: Protected routes require a valid JWT token in the Authorization header: Bearer <token>
src/
├── controllers/ # Route handlers and business logic
├── middleware/ # Authentication, validation, error handling
├── mysql/ # Database configuration and entities
├── routes/ # Express route definitions
├── services/ # External services (PokeAPI, JWT)
├── tests/ # Unit and integration tests
├── types/ # TypeScript type definitions
└── validators/ # Request validation schemas