First, make sure to create a .env file in the root project and fill it with the following format:
PORT=5000
DB_USER=postgres
DB_HOST=localhost
DB_NAME=(your db name)
DB_PASS=(your db password)
DB_PORT=(your cb port)
CLOUDINARY_NAME=(your cloudinary name)
CLOUDINARY_KEY=(your cloudinary key)
CLOUDINARY_SECRET=(your caludinary secret)
JWT_SECRET=(jwt secret)- Cloudinary credentials can be obtained from: https://cloudinary.com/
- JWT secret can be generated from: https://www.jwt.io/
Next, you can run the user_management_api by typing:
node index.js
# or
npm startIf successful, a message will appear in the terminal:
✅ Server running at http://localhost:5000After running and seeing the message "Server running on port 5000" in the terminal, enter the local host link http://localhost:5000/api/(auth or user)/(action for auth or user).
/api/auth/register POST Registrasi user baru
/api/auth/login POST Login dan mendapatkan JWT
/api/users GET Menampilkan semua user (dengan token)
/api/users/avatar POST Upload avatar user
/api/users/:id PUT Update user berdasarkan ID
/api/users/:id DELETE Hapus user berdasarkan IDcatatan: All /users endpoints require an Authorization header:
Authorization: Bearer <jwt_token>
see postman documentation here: https://documenter.getpostman.com/view/49108277/2sB3QRnSrq
After running, open your browser and go to the local host link:
http://localhost:5000/api-docsAfter opening it, an interactive documentation display with Swagger UI will appear.
Auth:
- In the auth section, register first.
- Next, log in and save the generated token.
- Insert the generated token into the Authorization header.
User: All user-related features can be executed directly since the token has already been added to the Authorization header.
- GET – Display all users
- POST – Upload user avatar
- PUT – Update user
- DELETE – Delete user