Prerequisites
Before you begin, ensure you have the following installed:- Node.js (v14 or higher)
- PostgreSQL (v12 or higher)
- npm or yarn package manager
Installation
Install dependencies
Install the required npm packages:This will install all dependencies from
package.json:express- Web frameworkpgandknex- PostgreSQL client and query buildermulter- File upload handlingexpress-jwtandjwks-rsa- Auth0 authenticationcors- CORS middlewareuuid- UUID generation
Set up environment variables
Create a
.env file in the project root with your configuration:.env
See the Environment Variables guide for detailed configuration instructions.
Run database migrations
Set up the database schema using Knex migrations:This creates the following tables:
images- Stores image metadatatags- Stores tags for categorizationitems- Stores catalog itemsitems_to_tags- Junction table for many-to-many relationships
Make Your First API Request
Now that your server is running, let’s make your first authenticated API request.All API endpoints require Auth0 JWT authentication. See the Authentication guide to obtain a valid token.
Upload an Image
Upload a cat image to the API:Upload Image
List All Images
Retrieve all uploaded images:List Images
Get a Specific Image
Retrieve an image by ID:Get Image
Delete an Image
Delete an image:Delete Image
204 No Content
Next Steps
Authentication
Learn how to authenticate with Auth0 JWT tokens
API Reference
Explore all available endpoints in detail
Database Schema
Understand the PostgreSQL database structure
Development Setup
Configure your development environment
Common Issues
Database connection errors
Database connection errors
If you see connection errors, verify:
- PostgreSQL is running:
pg_isready - Database credentials in
.envare correct - Database exists:
createdb cat_data
Authentication errors (401 Unauthorized)
Authentication errors (401 Unauthorized)
File upload errors
File upload errors
If file uploads fail, check:
- File type is JPEG or PNG (other types are rejected)
- File is being sent as multipart/form-data with field name
file - The
images/directory exists and is writable
Development Scripts
The API includes these npm scripts frompackage.json:
| Script | Command | Description |
|---|---|---|
dev | npm run dev | Start development server with hot reload |
build | npm run build | Compile TypeScript to JavaScript |
start | npm start | Run production server from compiled code |