Overview
DEMET Backend is a Node.js REST API for hotel reservation management built with Express, PostgreSQL, and modern security practices. This guide will walk you through setting up your development environment.Prerequisites
Before you begin, ensure you have the following installed:Node.js
Version 16.x or higher recommended
PostgreSQL
Version 12.x or higher required
npm
Comes bundled with Node.js
Git
For cloning the repository
Installation
Install Dependencies
Install all required npm packages:This will install the following key dependencies:
- express - Web framework
- pg - PostgreSQL client
- jsonwebtoken - JWT authentication
- bcrypt - Password hashing
- zod - Schema validation
- nodemailer - Email notifications
- exceljs - Report generation
- dotenv - Environment configuration
Configure Environment Variables
Create a Add your configuration (see Configuration Guide for details):
.env file in the root directory:Set Up the Database
Create your PostgreSQL database and run the schema migrations:See the Database Guide for detailed schema information.
Running the Server
Development Mode
For development with auto-reload on file changes:Production Mode
For production deployment:The server will start on the port specified in your
.env file (default: 3002)Verifying Installation
Once the server is running, you should see:Test the API
Visit the API documentation in your browser:Project Structure
Understanding the project layout:Server Configuration
The main server file (server.js) initializes:
CORS Configuration
The API is configured to accept requests from:- Production frontend:
https://clubmetabros.vercel.app - Local development:
http://localhost:3000
Common Issues
Database connection fails
Database connection fails
- Verify PostgreSQL is running
- Check
DATABASE_URLformat in.env - Ensure database exists and user has permissions
- Test connection:
psql $DATABASE_URL
Port already in use
Port already in use
Change the
PORT in your .env file or kill the process using the port:Module not found errors
Module not found errors
Delete
node_modules and reinstall:Email sending fails
Email sending fails
- Verify Gmail credentials in
.env - Enable “Less secure app access” or use App Passwords
- Check
GOOGLE_USERandGOOGLE_PWDvalues
Next Steps
Configuration
Learn about environment variables and configuration options
Database Schema
Understand the database structure and relationships
API Reference
Explore all available endpoints
Email Notifications
Configure email templates and sending