This backend API handles the core logic for a property renting platform, including user authentication, payment processing, property management, booking systems, and scheduled background tasks to automate order reminders, completions, and cleanups.
- Node.js: Runtime environment
- Express.js: Web framework for building APIs
- TypeScript: Typed superset of JavaScript
- Prisma: ORM for database management
- PostgreSQL: Relational database
- Cloudinary: Cloud storage for images and files
- Midtrans: Payment gateway integration
-
Install Dependencies:
npm install
-
Set Up Environment Variables:
- Copy
.env.exampleto.envand fill in the required values (see Environment Variables section below).
- Copy
-
Run Database Migrations:
npm run migrate:dev
-
Start the Development Server:
npm run dev
The application will run on the port specified in your .env file (default: 2000).
Create a .env file in the root directory with the following variables:
PORT=2000
NODE_ENV=development
LOCAL_DIRECT_URL=your_local_direct_url
JWT_ACCESS_SECRET=your_jwt_access_secret
JWT_REFRESH_SECRET=your_jwt_refresh_secret
DATABASE_URL=your_postgresql_database_url
DIRECT_URL=your_DIRECT_URL
DOMAIN_URL=your_domain_url
ACTIVATION_ACCOUNT_URL=your_activation_account_url
NODEMAILER_APP_EMAIL=your_nodemailer_email
NODEMAILER_APP_PASSWORD=your_nodemailer_password
CLOUD_NAME=your_cloudinary_cloud_name
CLOUD_API_KEY=your_cloudinary_api_key
CLOUD_API_SECRET=your_cloudinary_api_secret
CLOUD_PAYMENT_PROOF_FOLDER_PATH=your_payment_proof_folder
CLOUD_TEMP_PROPERTIES_IMAGE_FOLDER_PATH=your_temp_properties_folder
CLOUD_TENANT_PROFILE_FOLDER_PATH=your_tenant_profile_folder
MIDTRANS_SERVER_KEY=your_midtrans_server_key
MIDTRANS_CLIENT_KEY=your_midtrans_client_keyThis project uses Prisma as the ORM with PostgreSQL.
-
Run Migrations (for development):
npm run migrate:dev
-
Generate Prisma Client (after schema changes):
npx prisma generate
-
View Database (optional, requires Prisma Studio):
npx prisma studio
Scheduled background tasks are implemented using node-cron and must run as a separate service on Railway's Cron Job Service. These tasks include:
- Auto-cancel pending payments after 2 hours
- Send order reminders for upcoming check-ins
- Auto-complete orders after check-out
- Delete temporary images daily
Important: Do not run cron jobs in the main application process in production. Deploy them separately using Railway Cron Job Service with the following execution command:
node dist/src/cron/job.jsThis ensures background tasks run independently without affecting the main API performance.
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/login |
User login |
| GET | /auth/tenant-profile |
Get tenant profile |
| POST | /booking/create-order |
Create a booking order |
| GET | /booking/my-bookings |
Get user's booking list |
The application is configured for deployment on Railway. Ensure all environment variables are set in your Railway project settings, and configure the separate Cron Job Service for background tasks as described above.