Get started with DEMET Backend
This guide will help you set up the DEMET Backend API locally and make your first authenticated request. You’ll be up and running in less than 10 minutes.This quickstart assumes you have Node.js (v14+), PostgreSQL, and npm installed on your system.
Setup steps
Install dependencies
Install all required npm packages:This will install the following key dependencies:
express- Web frameworkpg- PostgreSQL clientjsonwebtoken- JWT authenticationbcrypt- Password hashingzod- Schema validationcookie-parser- Cookie handlingnodemailer- Email sendingexceljs- Excel report generation
Configure environment variables
Create a
.env file in the root directory with the following variables:.env
Set up the database
Ensure your PostgreSQL database is running and create the necessary tables and stored procedures. The database should have the following main tables:
employee- Employee accountspartner- Hotel partnersspace- Available spaces/roomsrate- Pricing informationextra- Additional servicesreservation- Booking records
The API uses stored procedures (e.g.,
p_insert_employee, p_update_employee) for database operations. Make sure these are properly set up in your PostgreSQL instance.Make your first API call
Now that the server is running, let’s make your first authenticated requests.Register an employee account
Create your first employee account with administrator privileges:The
/intern/signup endpoint requires authentication from an existing administrator. For the first account, you’ll need to create it directly in the database or modify the verifyRol middleware temporarily.Login and receive tokens
Authenticate with your newly created account:access_token- Valid for 1 hour (default)refresh_token- Valid for 7 days (default)
Make an authenticated request
Use the cookies from login to access protected endpoints:Get all spaces (public endpoint)
Some endpoints don’t require authentication. Try fetching all available spaces:Working with reservations
Create a new reservation with the authenticated session:Token refresh flow
When your access token expires (after 1 hour), you can refresh it without logging in again:access_token cookie while keeping the refresh_token unchanged.
Error handling
The API returns standard HTTP status codes and JSON error messages:Next steps
Authentication deep dive
Learn about the JWT authentication system, token lifecycle, and security best practices
API reference
Explore all available endpoints, request schemas, and response formats
Explore documentation
View the interactive Scalar API documentation at
http://localhost:3002/reference