Skip to main content

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

1

Clone the Repository

Clone the DEMET Backend repository from GitHub:
git clone https://github.com/ProyectoDemet/Backend-DEMET.git
cd Backend-DEMET
2

Install Dependencies

Install all required npm packages:
npm install
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
3

Configure Environment Variables

Create a .env file in the root directory:
touch .env
Add your configuration (see Configuration Guide for details):
DATABASE_URL=postgresql://user:password@localhost:5432/demet_db
ACCESS_SECRET=your-access-token-secret
ACCESS_EXPIRE_IN=1h
REFRESH_SECRET=your-refresh-token-secret
REFRESH_EXPIRE_IN=7d
PORT=3002
[email protected]
GOOGLE_PWD=your-app-specific-password
[email protected]
Never commit your .env file to version control. Add it to .gitignore.
4

Set Up the Database

Create your PostgreSQL database and run the schema migrations:
# Create database
createdb demet_db

# Run migrations (if available)
# Or import your database schema
psql demet_db < schema.sql
See the Database Guide for detailed schema information.

Running the Server

Development Mode

For development with auto-reload on file changes:
npm run dev
This uses nodemon to automatically restart the server when you make changes to your code.

Production Mode

For production deployment:
npm start
This runs the server with Node.js directly without auto-reload.
The server will start on the port specified in your .env file (default: 3002)

Verifying Installation

Once the server is running, you should see:
Servidor escuchando en http://localhost:3002

Test the API

Visit the API documentation in your browser:
http://localhost:3002/reference
You should see the interactive Scalar API documentation interface.

Project Structure

Understanding the project layout:
Backend-DEMET/
├── controller/          # Request handlers
│   ├── auth.controller.js
│   ├── reserve.controller.js
│   ├── report.controller.js
│   └── ...
├── routes/             # API route definitions
│   ├── auth.routes.js
│   ├── reserve.routes.js
│   └── ...
├── service/            # Business logic layer
│   ├── email.service.js
│   ├── excel.service.js
│   ├── report.service.js
│   └── ...
├── middleware/         # Express middlewares
│   ├── verifyToken.js
│   ├── rolAccess.js
│   └── validate.js
├── validator/          # Zod validation schemas
│   ├── reserve.schema.js
│   ├── auth.schema.js
│   └── ...
├── lib/               # Database connection
│   └── db.js
├── util/              # Utilities and templates
│   ├── templates/
│   └── errorHandler.js
├── server.js          # Application entry point
├── swagger.js         # API documentation
├── package.json       # Dependencies
└── .env              # Environment variables

Server Configuration

The main server file (server.js) initializes:
import express from "express";
import cors from 'cors';
import dotenv from 'dotenv';
import cookieParser from "cookie-parser";

dotenv.config();

const app = express();
const PORT = process.env.PORT || 3000;

// Middleware
app.use(cookieParser());
app.use(cors({
  origin: [
    "https://clubmetabros.vercel.app",
    "http://localhost:3000"
  ],
  credentials: true
}));
app.use(express.json());

// Routes
app.use('/intern', AuthRoutes);
app.use('/partner/', partnerRoutes);
app.use('/space/', spaceRoutes);
app.use('/rate/', rateRoutes);
app.use('/extra/', extraRoutes);
app.use('/reserve/', reserveRoutes);
app.use('/request/', requestRoutes);
app.use('/report/', reportRoutes);
app.use('/log/reserve/', logReserveRoutes);

// Start server
app.listen(PORT, "0.0.0.0", () => {
  console.log(`Servidor escuchando en http://localhost:${PORT}`);
});

CORS Configuration

The API is configured to accept requests from:
  • Production frontend: https://clubmetabros.vercel.app
  • Local development: http://localhost:3000
Credentials (cookies) are enabled for JWT token handling.

Common Issues

  • Verify PostgreSQL is running
  • Check DATABASE_URL format in .env
  • Ensure database exists and user has permissions
  • Test connection: psql $DATABASE_URL
Change the PORT in your .env file or kill the process using the port:
# Find process on port 3002
lsof -i :3002

# Kill the process
kill -9 <PID>
Delete node_modules and reinstall:
rm -rf node_modules package-lock.json
npm install
  • Verify Gmail credentials in .env
  • Enable “Less secure app access” or use App Passwords
  • Check GOOGLE_USER and GOOGLE_PWD values

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

Build docs developers (and LLMs) love