Documentation Index Fetch the complete documentation index at: https://mintlify.com/andreguti9190/Sistema-de-gestion-de-ventas--Nodejs/llms.txt
Use this file to discover all available pages before exploring further.
Installation
This guide will walk you through installing and configuring the Sales Management System API.
System Requirements
Before installing, ensure your system meets these requirements:
Node.js : v14.0.0 or higher
MySQL : v5.7 or higher
npm : v6.0.0 or higher (comes with Node.js)
Operating System : Linux, macOS, or Windows
Memory : Minimum 512MB RAM
Disk Space : At least 100MB free
Clone Repository
Clone the repository to your local machine:
git clone < repository-ur l >
cd sistema-de-gestion-de-ventas
Install Dependencies
The project uses the following npm packages:
Core Dependencies
From package.json:
express (^5.2.1) - Fast, minimalist web framework for Node.js
mysql2 (^3.17.3) - MySQL client with promises and prepared statements
zod (^4.3.6) - TypeScript-first schema validation library
The project uses ES modules ("type": "module" in package.json), so all imports use ES6 syntax.
Database Setup
Create Database
Connect to your MySQL server and create the database:
Then execute:
CREATE DATABASE erpDB ;
USE erpDB;
Import Schema
The complete database schema is located in src/model/database.sql. You can import it directly:
mysql -u root -p erpDB < src/model/database.sql
Or execute the SQL manually:
-- Roles table
CREATE TABLE roles (
id INT AUTO_INCREMENT PRIMARY KEY ,
name VARCHAR ( 50 ) NOT NULL UNIQUE
);
INSERT INTO roles ( name ) VALUES ( 'admin' ), ( 'employee' );
-- Users table
CREATE TABLE users (
id BINARY ( 16 ) PRIMARY KEY ,
name VARCHAR ( 100 ) NOT NULL ,
email VARCHAR ( 150 ) NOT NULL UNIQUE ,
password VARCHAR ( 255 ) NOT NULL ,
role_id INT NOT NULL ,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (role_id) REFERENCES roles(id)
);
-- Clients table
CREATE TABLE clients (
id BINARY ( 16 ) PRIMARY KEY ,
name VARCHAR ( 100 ) NOT NULL ,
email VARCHAR ( 150 ) NOT NULL UNIQUE
);
-- Categories table
CREATE TABLE categories (
id INT AUTO_INCREMENT PRIMARY KEY ,
name VARCHAR ( 100 ) NOT NULL UNIQUE ,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Products table
CREATE TABLE products (
id BINARY ( 16 ) PRIMARY KEY ,
name VARCHAR ( 150 ) NOT NULL ,
description TEXT ,
price DECIMAL ( 10 , 2 ) NOT NULL ,
stock INT NOT NULL DEFAULT 0 ,
category_id INT ,
is_deleted BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES categories(id)
);
-- Sales table
CREATE TABLE sales (
id BINARY ( 16 ) PRIMARY KEY ,
clients_id BINARY ( 16 ) NOT NULL ,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (clients_id) REFERENCES clients(id)
);
-- Sale details table
CREATE TABLE sale_details (
id BINARY ( 16 ) PRIMARY KEY ,
sale_id BINARY ( 16 ) NOT NULL ,
product_id BINARY ( 16 ) NOT NULL ,
quantity INT NOT NULL ,
FOREIGN KEY (sale_id) REFERENCES sales(id) ON DELETE CASCADE ,
FOREIGN KEY (product_id) REFERENCES products(id)
);
Make sure to create tables in the order shown above to satisfy foreign key constraints.
Verify Database Setup
Verify all tables were created:
You should see:
+------------------+
| Tables_in_erpDB |
+------------------+
| categories |
| clients |
| products |
| roles |
| sale_details |
| sales |
| users |
+------------------+
Environment Configuration
Configure database connection settings in src/config.js:
export default {
PORT: 3000 ,
HOST_DATABASE: "localhost" ,
PORT_DATABASE: 3306 ,
DATABASE_NAME: "erpDB" ,
PASSWORD_DATABASE: "admin" ,
USER_DATABASE: "root"
}
Configuration Parameters
Parameter Description Default PORTApplication server port 3000 HOST_DATABASEMySQL host address localhost PORT_DATABASEMySQL port 3306 DATABASE_NAMEDatabase name erpDB USER_DATABASEMySQL username root PASSWORD_DATABASEMySQL password admin
Security Best Practice : In production, use environment variables instead of hardcoding credentials. Never commit sensitive credentials to version control.
Using Environment Variables (Recommended)
Create a .env file:
PORT = 3000
DB_HOST = localhost
DB_PORT = 3306
DB_NAME = erpDB
DB_USER = root
DB_PASSWORD = your_secure_password
Then update config.js to use environment variables:
export default {
PORT: process . env . PORT || 3000 ,
HOST_DATABASE: process . env . DB_HOST || "localhost" ,
PORT_DATABASE: process . env . DB_PORT || 3306 ,
DATABASE_NAME: process . env . DB_NAME || "erpDB" ,
PASSWORD_DATABASE: process . env . DB_PASSWORD || "admin" ,
USER_DATABASE: process . env . DB_USER || "root"
}
Verify Installation
Start the Server
Run the development server with auto-reload:
The dev script uses Node.js --watch flag for automatic restart on file changes.
You should see:
Server on port http://localhost:3000
Test API Endpoint
Test that the API is responding:
curl http://localhost:3000/categories
Expected response:
{
"error" : false ,
"categorieList" : []
}
Test Database Connection
Create a test category to verify database connectivity:
curl -X POST http://localhost:3000/categories \
-H "Content-Type: application/json" \
-d '{"name":"test"}'
Expected response:
{
"error" : false ,
"msg" : "categorie was created sucessfully"
}
Troubleshooting
Connection refused errors
Verify MySQL is running: sudo systemctl status mysql
Check MySQL is listening on port 3306: netstat -an | grep 3306
Verify credentials in config.js are correct
Ensure MySQL user has proper permissions:
GRANT ALL PRIVILEGES ON erpDB. * TO 'root' @ 'localhost' ;
FLUSH PRIVILEGES;
Change the PORT in config.js to a different value (e.g., 3001)
Or kill the process using port 3000:
lsof -ti:3000 | xargs kill -9
Delete node_modules and reinstall:
rm -rf node_modules package-lock.json
npm install
Next Steps
Quickstart Guide Make your first API requests
Configuration Guide Advanced configuration options
API Reference Explore all endpoints
Database Schema Understand the data model