A simple backend API for a library management system, built using Node.js, Express, and MySQL. It includes features for user authentication, book and member management, and book lending functionality.
- 🧑💼 Petugas (Staff) Registration and Login (JWT authentication)
- 📖 CRUD for Books
- 👤 CRUD for Members
- ↻ Borrowing and Returning Books
- 🔐 Protected Endpoints via Token
- ⚖️ Modular REST API structure
- Node.js + Express
- MySQL (with mysql2)
- JWT for authentication
- bcryptjs for password hashing
- dotenv for environment config
- CORS enabled
git clone https://github.com/username/node-library.git
cd node-librarynpm installAPP_PORT=3000
DB_HOST=localhost
DB_USER=YOUR_USER
DB_PASS=YOUR_PASS
DB_PORT=3306
MYSQL_DB=tes_perpusUse MySQL Workbench or phpMyAdmin to import the provided SQL dump or manually create these tables:
tb_petugastb_bukutb_anggotatb_pinjam
node app.jsThe server runs at:
http://localhost:3000
After login, a token is returned:
{
"token": "eyJhbGciOiJIUzI1NiIs..."
}Use this token in headers:
Authorization: Bearer <token>
POST /api/petugas
POST /api/petugas/login
GET /api/buku
├── api/
│ ├── buku/
│ ├── anggota/
│ ├── petugas/
│ └── pinjam/
├── config/
│ └── database.js
├── .env
├── app.js
├── package.json
Ghufron Andriansyah Made for learning and backend API development using Node.js
- No frontend UI included
- JWT token expires in 1 hour
- Passwords are securely hashed using bcryptjs