Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/brandonvergara1220-del/Mini-Proyecto-Backend-NodeJS/llms.txt

Use this file to discover all available pages before exploring further.

Mini Proyecto Backend NodeJS connects to a local MySQL database named ejemploformulario. Before running the application for the first time, you must create the database, create the required table, and ensure that the credentials in conexion.js match your local MySQL installation. This page walks through every step from a fresh MySQL installation to a working database connection.

Prerequisites

  • MySQL 5.7+, MariaDB 10.3+, or any compatible MySQL-protocol server installed and available on your machine.
  • The mysql command-line client, MySQL Workbench, or another SQL client to execute the setup queries.
  • The project cloned and npm install completed (see Environment Configuration).

Setup Steps

1

Start the MySQL Server

Make sure the MySQL service is running before attempting to connect.Linux (systemd):
sudo systemctl start mysql
# Verify it is running
sudo systemctl status mysql
macOS (Homebrew):
brew services start mysql
Windows (Command Prompt as Administrator):
net start MySQL80
Replace MySQL80 with the actual service name shown in Windows Services if yours differs (e.g. MySQL57 or MariaDB).
2

Create the Database

Log in to the MySQL shell and create the ejemploformulario database:
mysql -u root -p
Once inside the MySQL prompt, run:
CREATE DATABASE IF NOT EXISTS ejemploformulario
  CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;

USE ejemploformulario;
The IF NOT EXISTS clause makes the statement safe to run more than once — it will not raise an error if the database already exists.
3

Create the usuarios Table

While still connected to ejemploformulario, create the usuarios table that the registration form writes to:
CREATE TABLE IF NOT EXISTS usuarios (
  id          INT AUTO_INCREMENT PRIMARY KEY,
  nombre      VARCHAR(100) NOT NULL,
  apellido    VARCHAR(100) NOT NULL,
  created_at  TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
ColumnTypeDescription
idINT AUTO_INCREMENTUnique identifier, generated automatically for each row
nombreVARCHAR(100)First name submitted by the registration form
apellidoVARCHAR(100)Last name submitted by the registration form
created_atTIMESTAMPDate and time the record was inserted, set automatically
You can verify the table was created correctly with:
DESCRIBE usuarios;
4

Update conexion.js with Your Credentials

Open conexion.js and confirm (or update) the connection parameters to match your MySQL installation:
conexion.js
let mysql = require('mysql2');

let conexion = mysql.createConnection({
  host: "localhost",
  database: "ejemploformulario",
  user: "root",
  password: ""
});

conexion.connect(function(error) {
  if (error) {
    throw error;
  } else {
    console.log("Conexión exitosa a la base de datos");
  }
});

module.exports = conexion;
If your MySQL root user has a password set, replace the empty string "" with that password. If you are using a dedicated application user (recommended — see the tip below), replace both user and password accordingly.

Connection Parameters Reference

The mysql.createConnection() call in conexion.js accepts the following options used by this project:
ParameterCurrent ValueDescription
host"localhost"Hostname or IP address of the MySQL server. Use "localhost" or "127.0.0.1" for a local installation.
database"ejemploformulario"The database to select automatically upon connecting. Must exist before the app starts.
user"root"MySQL username used to authenticate.
password""Password for the specified user. An empty string means no password is set.
The default configuration connects as root with an empty password. This is only safe on a local development machine that is not accessible from the network. MySQL installations on Linux often require at least a socket-authenticated root session, which may mean you need to set a password or create a separate user even for local development.
Instead of using the root account for your application, create a dedicated MySQL user with only the permissions it needs:
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'a_strong_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON ejemploformulario.* TO 'app_user'@'localhost';
FLUSH PRIVILEGES;
Then update the user and password fields in conexion.js (or your .env file) to use app_user. Limiting database privileges reduces the blast radius of any SQL injection vulnerability or accidental query.

Build docs developers (and LLMs) love