Skip to main content

Quickstart Guide

Get the SSP Backend API up and running quickly with this step-by-step guide. You’ll have a working API server in under 5 minutes.

Prerequisites

Before you begin, ensure you have the following installed:
  • Node.js (v18 or higher)
  • npm (comes with Node.js)
  • PostgreSQL (v12 or higher)
  • Git (for cloning the repository)

Installation Steps

1

Clone the Repository

Clone the SSP Backend API repository to your local machine:
git clone <repository-url>
cd ssp_back
2

Install Dependencies

Install all required npm packages:
npm install
This will install NestJS, TypeORM, PostgreSQL driver, JWT libraries, and all other dependencies defined in package.json.
3

Configure Environment Variables

Create a .env file in the root directory with your database and JWT configuration:
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=your_password
DB_NAME=ssp_db

# JWT Configuration
JWT_SECRET=your_secret_key_change_me_in_production
JWT_EXPIRES_IN=1d

# Server Configuration
PORT=3000

# Seed Admin Password (optional)
SEED_ADMIN_PASSWORD=Admin1234
Always use strong, unique values for JWT_SECRET in production environments. Never commit .env files to version control.
4

Create PostgreSQL Database

Create a new PostgreSQL database for the application:
# Using psql command line
psql -U postgres
CREATE DATABASE ssp_db;
\q
Or use your preferred PostgreSQL GUI tool (pgAdmin, DBeaver, etc.).
5

Run Database Migrations

TypeORM will automatically run migrations on startup because migrationsRun: true is configured in src/app.module.ts:24.The application is configured to:
  • Auto-load entities
  • Run migrations automatically
  • Not synchronize schema (for safety)
6

Seed Initial Admin User

Create an initial admin user to access the system:
npm run seed:admin
This creates an admin user with:
  • Username: Admin
  • Password: Admin1234 (or the value of SEED_ADMIN_PASSWORD from .env)
  • Role: Admin
The seed script checks if the admin already exists and won’t create duplicates. You’ll see ”✅ Admin ya existe: Admin” if the user already exists.
7

Start the Development Server

Start the API server in development mode:
npm run start:dev
The server will start on port 3000 (or the PORT specified in .env) with hot-reload enabled.You should see output like:
[Nest] 12345  - 03/05/2026, 10:00:00 AM     LOG [NestFactory] Starting Nest application...
[Nest] 12345  - 03/05/2026, 10:00:00 AM     LOG [InstanceLoader] AppModule dependencies initialized
[Nest] 12345  - 03/05/2026, 10:00:00 AM     LOG [NestApplication] Nest application successfully started

Make Your First API Call

Now that the server is running, let’s authenticate and make your first API call.

1. Login to Get JWT Token

Send a POST request to the login endpoint:
curl -X POST http://localhost:3000/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "nomUsuario": "Admin",
    "contrasena": "Admin1234"
  }'
Response:
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": 1,
    "nombre": "Admin Principal",
    "rol": "Admin",
    "nomUsuario": "Admin"
  }
}
Copy the access_token value - you’ll need it for authenticated requests.

2. Make an Authenticated Request

Use the JWT token to access protected endpoints. For example, list all users:
curl -X GET http://localhost:3000/users \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN_HERE"
Response:
[
  {
    "id": 1,
    "nombre": "Admin Principal",
    "rol": "Admin",
    "nomUsuario": "Admin",
    "estatus": true,
    "creadoEn": "2026-03-05T10:00:00.000Z"
  }
]
Replace YOUR_ACCESS_TOKEN_HERE with the actual token from the login response.

Testing the API

You can test the API using:
  • cURL (as shown above)
  • Postman or Insomnia (import the endpoints)
  • HTTPie - A user-friendly HTTP client
  • Thunder Client or REST Client (VS Code extensions)

What’s Next?

Authentication Guide

Learn how JWT authentication and role-based access control work

Database Setup

Deep dive into PostgreSQL configuration and TypeORM entities

Environment Variables

Complete reference of all configuration options

API Reference

Explore all available API endpoints and operations

Troubleshooting

Ensure PostgreSQL is running and the credentials in .env are correct:
# Check if PostgreSQL is running
sudo systemctl status postgresql

# Or on macOS
brew services list | grep postgresql
Verify your database credentials and that the database exists.
If port 3000 is already in use, change the PORT in your .env file:
PORT=3001
Or find and kill the process using port 3000:
# Find process
lsof -i :3000

# Kill process
kill -9 <PID>
JWT tokens expire after the duration specified in JWT_EXPIRES_IN (default: 1 day). Simply login again to get a new token:
curl -X POST http://localhost:3000/auth/login \
  -H "Content-Type: application/json" \
  -d '{"nomUsuario": "Admin", "contrasena": "Admin1234"}'

Build docs developers (and LLMs) love