CRUD -> Vue.js + Node.js + PostgreSQL
A full-stack CRUD
π¦ Product Management CRUD - Vue.js + Node.js + PostgreSQL
A full-stack CRUD (Create, Read, Update, Delete) application for managing products, built with Vue.js 3 (Composition API) on the frontend and Node.js + Express + PostgreSQL on the backend.
π Features
- β Create new products
- π List all products in a table
- βοΈ Update existing products
- ποΈ Delete products
- πΎ PostgreSQL database integration
- π¨ Modern and responsive UI
πΈ Screenshots
π οΈ Tech Stack
Backend
- Node.js - JavaScript runtime
- Express.js - Web framework
- PostgreSQL - Relational database
- pg - PostgreSQL client for Node.js
- cors - Enable CORS
- dotenv - Environment variables
Frontend
- Vue.js 3 - Progressive JavaScript framework
- Composition API - Modern Vue syntax
- Axios - HTTP client
π Prerequisites
Before you begin, ensure you have the following installed:
- Node.js (v14 or higher)
- PostgreSQL (v12 or higher)
- npm or yarn package manager
ποΈ Database Setup
1. Create the Database
Open PostgreSQL terminal (psql) and run:
CREATE DATABASE crud_vue;
2. Create the User
CREATE USER psy_support_user WITH PASSWORD 'dev_password_123';
3. Grant Permissions
GRANT ALL PRIVILEGES ON DATABASE crud_vue TO psy_support_user;
4. Connect to the Database
\c crud_vue
5. Create the Products Table
CREATE TABLE productos (
id SERIAL PRIMARY KEY,
nombre VARCHAR(100) NOT NULL,
descripcion TEXT,
precio DECIMAL(10, 2) NOT NULL,
stock INTEGER DEFAULT 0
);
6. Insert Sample Data (Optional)
INSERT INTO productos (nombre, descripcion, precio, stock) VALUES
('Laptop HP', 'Laptop de alto rendimiento', 899.99, 15),
('Mouse Logitech', 'Mouse inalΓ‘mbrico ergonΓ³mico', 29.99, 50),
('Teclado MecΓ‘nico', 'Teclado RGB con switches azules', 79.99, 30);
βοΈ Backend Installation
1. Navigate to Backend Directory
cd backend
2. Install Dependencies
npm install
This will install:
- express
- pg
- cors
- dotenv
3. Configure Database Connection
Edit config/database.js if needed to match your PostgreSQL configuration:
const pool = new Pool({
user: 'psy_support_user',
host: 'localhost',
database: 'crud_vue',
password: 'dev_password_123',
port: 5433 // Change to 5432 if using default PostgreSQL port
})
4. Start the Backend Server
node index.js
The server will run on http://localhost:3000
You should see:
π Servidor Express funcionando en el puerto 3000
URL de prueba: http://localhost:3000
5. Test the API
Open your browser and visit:
-
http://localhost:3000/- Should return:{"mensaje": "API funcionando correctamente"} -
http://localhost:3000/api/productos- Should return the list of products
π¨ Frontend Installation
1. Navigate to Frontend Directory
cd frontend
2. Install Dependencies
npm install
This will install Vue.js, Axios, and other dependencies.
3. Configure API URL
The API URL is already configured in src/services/productosService.js:
const API_URL = 'http://localhost:3000/api/productos';
4. Start the Development Server
npm run dev
The application will run on http://localhost:5173 (or another port if 5173 is busy)
5. Open in Browser
Visit http://localhost:5173 to use the application
π Project Structure
crud-vue-postgres/
β
βββ backend/
β βββ config/
β β βββ database.js # PostgreSQL connection configuration
β βββ controllers/
β β βββ productosController.js # Business logic for CRUD operations
β βββ routes/
β β βββ productos.js # API routes definition
β βββ index.js # Express server entry point
β βββ package.json
β
βββ frontend/
β βββ src/
β β βββ components/
β β β βββ ProductosCRUD.vue # Main CRUD component
β β βββ services/
β β β βββ productosService.js # API service layer
β β βββ App.vue # Root component
β βββ package.json
β
βββ screens/ # Application screenshots
βββ Main.png
βββ tabla.png
βββ New product.png
βββ Update product.png
βββ Delete product.png
βββ Delete product 2.png
π API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/productos | Get all products |
| GET | /api/productos/:id | Get a single product by ID |
| POST | /api/productos | Create a new product |
| PUT | /api/productos/:id | Update a product by ID |
| DELETE | /api/productos/:id | Delete a product by ID |
Example Request Body (POST/PUT)
{
"nombre": "Product Name",
"descripcion": "Product Description",
"precio": 99.99,
"stock": 10
}
π― Usage
Creating a Product
- Fill in the form fields (Name, Description, Price, Stock)
- Click the ββ Crearβ button
- The product will appear in the table below
Editing a Product
- Click the ββοΈβ button on any product row
- The form will populate with the product data
- Modify the fields as needed
- Click βπΎ Actualizarβ to save changes
Deleting a Product
- Click the βποΈβ button on any product row
- Confirm the deletion in the popup dialog
- The product will be removed from the database
π Troubleshooting
Backend Issues
Port already in use:
# Change the PORT in backend/.env or index.js
const PORT = process.env.PORT || 3001;
Database connection error:
- Verify PostgreSQL is running:
sudo service postgresql status - Check database credentials in
config/database.js - Ensure the database and table exist
CORS errors:
- Ensure
cors()middleware is enabled inindex.js - Check the frontend is making requests to the correct URL
Frontend Issues
API connection error:
- Verify the backend server is running on port 3000
- Check the API_URL in
src/services/productosService.js - Open browser console to see detailed error messages
Module not found:
# Delete node_modules and reinstall
rm -rf node_modules
npm install
π Environment Variables (Optional)
Create a .env file in the backend directory:
PORT=3000
DB_USER=psy_support_user
DB_HOST=localhost
DB_DATABASE=crud_vue
DB_PASSWORD=dev_password_123
DB_PORT=5433
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
π License
This project is open source and available under the MIT License.
π¨βπ» Author
Your Name - Your GitHub Profile
π Acknowledgments
- Vue.js Documentation
- Express.js Documentation
- PostgreSQL Documentation
Made with β€οΈ using Vue.js, Node.js, and PostgreSQL