Skip to main content

Prerequisites

Before you begin, ensure you have:
  • Node.js (v14 or higher)
  • Docker and Docker Compose
  • Git
  • A text editor or IDE
  • curl or Postman for testing

Setup Steps

1

Clone the Repository

Clone the App CR repository to your local machine:
git clone <your-repository-url>
cd app-cr
2

Start PostgreSQL with Docker

Launch the PostgreSQL database using Docker Compose:
docker-compose up -d
This will start a PostgreSQL container with the following configuration:
  • User: user_admin
  • Password: password123
  • Database: mi_db_crud
  • Port: 5432
The -d flag runs the container in detached mode (background).
3

Configure Environment Variables

Create a .env file in the backend directory:
cd backend
touch .env
Add the following environment variables:
DATABASE_URL="postgresql://user_admin:password123@localhost:5432/mi_db_crud"
JWT_SECRET="your-secret-key-here"
PORT=3000
Replace your-secret-key-here with a strong, random secret key for production use.
4

Install Dependencies

Install all required npm packages:
npm install
This installs:
  • Express.js for the web server
  • Prisma for database ORM
  • bcryptjs for password hashing
  • jsonwebtoken for JWT authentication
  • Other essential dependencies
5

Initialize the Database

Generate Prisma client and run migrations:
npx prisma generate
npx prisma migrate dev --name init
This creates the database tables based on your schema:
  • User table
  • Task table
6

Start the Server

Launch the Express.js server:
node index.js
You should see:
Servidor corriendo en: http://localhost:3000
The server runs on port 3000 by default. You can change this in your .env file.

Make Your First API Call

Now that your server is running, let’s create a user!
curl -X POST http://localhost:3000/usuarios \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "mypassword123"
  }'

Expected Response

If successful, you’ll receive a 201 Created response with the user data:
{
  "id": 1,
  "email": "user@example.com",
  "password": "mypassword123"
}
The current implementation stores passwords in plain text. For production use, you should implement password hashing with bcryptjs before storing user credentials.

Verify Your Setup

Check that everything is working:
1

Database Connection

Verify PostgreSQL is running:
docker ps
You should see a container with the postgres:15 image.
2

Server Status

Check that the Express server is responding:
curl http://localhost:3000/usuarios
3

Prisma Studio (Optional)

Open Prisma Studio to view your database visually:
npx prisma studio
This opens a browser interface at http://localhost:5555.

Next Steps

Installation Guide

Detailed setup and configuration options

API Reference

Complete API endpoint documentation

Troubleshooting

If you have another PostgreSQL instance running, either stop it or change the port in docker-compose.yml:
ports:
  - "5433:5432"
Don’t forget to update your DATABASE_URL accordingly.
If migrations fail, reset the database:
npx prisma migrate reset
npx prisma migrate dev --name init
Ensure Docker is running and the PostgreSQL container is up:
docker-compose ps
docker-compose logs postgres

Build docs developers (and LLMs) love