Skip to main content

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

1

Clone the repository

Clone the Cat Data API repository to your local machine:
git clone https://github.com/toryshchyn/cat-data.git
cd cat-data
2

Install dependencies

Install all required Node.js packages:
npm install
The project uses the following key dependencies:
  • Express - Web framework
  • Knex - SQL query builder
  • PostgreSQL (pg) - Database driver
  • Auth0 - Authentication (express-jwt, jwks-rsa)
  • Multer - File upload handling
  • TypeScript - Type safety
3

Configure environment variables

Create a .env file in the root directory with your configuration:
# Database Configuration
PGHOST=localhost
PGPORT=5432
PGUSER=your_username
PGPASSWORD=your_password
PGDATABASE=cat_data

# Auth0 Configuration
AUTH0_DOMAIN=https://your-domain.auth0.com/
AUTH0_AUDIENCE=your-api-audience

# Server Configuration
PORT=3000
NODE_ENV=development
See the Environment Variables page for detailed configuration options.
4

Create the database

Create a PostgreSQL database for the application:
createdb cat_data
Or using psql:
CREATE DATABASE cat_data;
5

Run database migrations

Set up the database schema by running migrations:
npx knex migrate:latest
This will create all necessary tables (images, tags, items, items_to_tags).
Learn more about database migrations in the Migrations guide.
6

Start the development server

Start the API server in development mode:
npm run dev
The server will start with hot-reloading enabled using ts-node-dev. You should see:
Server running on http://localhost:3000

Available Scripts

The following npm scripts are available in package.json:
npm run dev
  • npm run dev - Starts the development server with hot-reloading using ts-node-dev
  • npm run build - Compiles TypeScript to JavaScript in the dist directory
  • npm start - Runs the compiled production build from dist/index.js

Project Structure

After setup, your project structure will look like this:
cat-data/
├── src/
│   ├── index.ts              # Main application entry point
│   ├── db.ts                 # Database connection
│   ├── db-functions.ts       # Database queries
│   └── middlewares/
│       └── checkJwt.ts       # Auth0 JWT middleware
├── migrations/               # Database migration files
├── images/                   # Uploaded image storage
├── knexfile.js              # Knex configuration
├── package.json             # Dependencies and scripts
├── tsconfig.json            # TypeScript configuration
└── .env                     # Environment variables

Verify Installation

Test that everything is working:
  1. Check the root endpoint:
    curl http://localhost:3000
    
    Expected response:
    Hello from CAT API
    
  2. Verify database connection: Check that all tables were created:
    psql -d cat_data -c "\dt"
    
    You should see: images, tags, items, and items_to_tags tables.
The protected API endpoints (/api/images, /api/upload, etc.) require valid Auth0 JWT tokens. Make sure your Auth0 configuration is correct before testing authenticated routes.

Next Steps

Build docs developers (and LLMs) love