API backend untuk manajemen data obat menggunakan Node.js, Express, dan Supabase.
- Node.js
- npm
- Akun Supabase dan project Supabase sudah dibuat
- Clone repo
git clone https://github.com/princeofverry/create-api-medication.git
cd create-api-medication
- Install dependencies
npm install
- Buat file
.env
- Copy dari
.env.example
cp .env.example .env
- Edit
.env
dan isi sesuai project Supabase kamu:
SUPABASE_URL=your_supabase_url
SUPABASE_KEY=your_supabase_anon_key
PORT=3000
- Jalankan API
npm run dev # untuk development
npm start # untuk production
- Tes endpoint
- Buka di browser atau Postman:
GET http://localhost:3000/api/medications
src/
├─ index.js # Entry point API
├─ models/
│ └─ medication.js
└─ config/
└─ supabaseClient.js
package.json
.env.example
- Buka postman
- Import file
praktikum-ppb-1.postman_collection.json
- Jalankan collection
create table categories (
id uuid primary key default gen_random_uuid(),
name text not null
);
create table suppliers (
id uuid primary key default gen_random_uuid(),
name text not null,
phone text,
email text
);
create table medications (
id uuid primary key default gen_random_uuid(),
sku text unique,
name text not null,
description text,
category_id uuid references categories(id),
supplier_id uuid references suppliers(id),
price numeric(12,2) default 0,
quantity integer default 0
);
- Jangan commit
.env
ke repo, gunakan.env.example
sebagai template. - Pastikan Supabase sudah memiliki tabel
medications
dan data sudah ada.