Skip to main content

Get started with Juadah API

This guide will help you set up the Juadah API locally and make your first API request. You’ll have a working API server running in just a few minutes.
1

Clone the repository

First, clone the Juadah backend repository to your local machine:
git clone https://github.com/yourusername/juadah-backend.git
cd juadah-backend
Make sure you have Node.js v20 or higher installed on your system.
2

Install dependencies

Install all required npm packages:
npm install
This will install all dependencies including:
  • Express for the web framework
  • Prisma for database ORM
  • TypeScript for type safety
  • Zod for validation
  • And other essential packages
The postinstall script will automatically run prisma generate to create the Prisma client.
3

Configure environment variables

Create a .env file in the root directory by copying the example file:
cp .env.example .env
Then configure the following required variables in your .env file:
.env
# Database Configuration
DATABASE_URL="postgresql://user:password@localhost:5432/juadah"
DIRECT_URL="postgresql://user:password@localhost:5432/juadah"

# Server Configuration
SERVER_PORT=3000

# JWT Secret (use a strong random string)
TOKEN_SECRET="your-secret-key-here"

# Email Configuration
EMAIL="your-email@example.com"
EMAIL_PASSWORD="your-email-password"

# Midtrans Payment Gateway
MIDTRANS_SERVER_KEY="your-midtrans-server-key"
MIDTRANS_BASE_URL="https://api.sandbox.midtrans.com"

# Cloudinary for Image Uploads
CLOUDINARY_CLOUD_NAME="your-cloud-name"
CLOUDINARY_API_KEY="your-api-key"
CLOUDINARY_API_SECRET="your-api-secret"
Never commit your .env file to version control. It contains sensitive credentials.
4

Set up the database

Make sure PostgreSQL is running, then run the Prisma migrations to set up your database schema:
npx prisma migrate deploy
This will create all necessary tables including:
  • users - User accounts with authentication
  • products - Bakery products catalog
  • orders - Customer orders and transactions
  • ratings - Product reviews and ratings
  • adresses - Customer delivery addresses
You can view your database using Prisma Studio:
npx prisma studio
5

Start the development server

Launch the API server in development mode:
npm run dev
You should see output indicating the server is running:
Server running at port 3000
The API will be available at http://localhost:3000/api/
The development server uses ts-node-dev which automatically restarts when you make code changes.

Make your first API call

Now that your server is running, let’s make your first API call by registering a new user.

Register a new user

Use this curl command to create a new user account:
curl -X POST http://localhost:3000/api/register \
  -H "Content-Type: application/json" \
  -d '{
    "fullname": "John Doe",
    "email": "john@example.com",
    "password": "securePassword123",
    "passwordConfirmation": "securePassword123"
  }'
curl -X POST http://localhost:3000/api/register \
  -H "Content-Type: application/json" \
  -d '{
    "fullname": "John Doe",
    "email": "john@example.com",
    "password": "securePassword123",
    "passwordConfirmation": "securePassword123"
  }'

Login to get access tokens

After registering, login to receive JWT tokens:
curl -X POST http://localhost:3000/api/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "john@example.com",
    "password": "securePassword123"
  }'
The response will include an access token and set a refresh token cookie that you’ll use for authenticated requests.

Fetch products (authenticated request)

Use the access token from the login response to fetch products:
curl -X GET http://localhost:3000/api/products \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Replace YOUR_ACCESS_TOKEN with the actual token received from the login response.

Explore the API documentation

The Juadah API includes built-in Swagger documentation. Once your server is running, visit:
http://localhost:3000/api/docs
This interactive documentation allows you to:
  • Explore all available endpoints
  • View request/response schemas
  • Test API calls directly from your browser
  • Understand authentication requirements

Next steps

Authentication Guide

Learn about JWT authentication and refresh tokens

Product Management

Create and manage bakery products with images

Payment Integration

Integrate Midtrans for payment processing

API Reference

View complete API endpoint documentation

Running tests

The Juadah API includes a comprehensive test suite. Run tests with:
npm run test
All tests must pass before merging any pull requests. Write unit tests for any new features you implement.

Development tools

The project includes several helpful npm scripts:
# Run development server with auto-reload
npm run dev

# Build for production
npm run build

# Start production server
npm start

# Run linter
npm run lint

# Fix linting issues
npm run fix-lint

# Format code
npm run format

# Run tests
npm run test

Need help?

If you encounter any issues or have questions:
  • Check the API Reference for detailed endpoint documentation
  • Review the Authentication Guide for auth-related issues
  • Open an issue on the GitHub repository
  • Review the Swagger documentation at /api/docs