Building a MySQL Database Connection with Node.js and Express
DBeaver Community is a free, open-source database management tool recommended for personal projects.
Create a new connection
- Run this query to create a new database:
CREATE DATABASE IF NOT EXISTS testdb;- Run this query to use the above created database:
USE testdb;- Run this create query to create a new table named users:
CREATE TABLE IF NOT EXISTS users (
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL
);- After the creation of the table run this command to insert some values into this table:
INSERT INTO users(name, email) VALUES
('John Doe', 'john.doe@example.com'),
('Jane Smith', 'jane.smith@example.com'),
('Alice Johnson', 'alice.johnson@example.com'),
('Bob Brown', 'bob.brown@example.com'),
('Charlie Davis', 'charlie.davis@example.com'),
('Eve White', 'eve.white@example.com'),
('Frank Black', 'frank.black@example.com'),
('Grace Green', 'grace.green@example.com'),
('Hank Blue', 'hank.blue@example.com'),
('Ivy Yellow', 'ivy.yellow@example.com');
.env file
DB_HOST=127.0.0.1
DB_USER=root
DB_PASSWORD="DBeaver root password"
DB_DATABASE="your database"
DB_PORT=3306
PORT=8001GET http://localhost:8001/members
POST http://localhost:8001/members
body JSON :
{ "name": "Ismael", "email": "test@example.com" }PUT http://localhost:8001/members/1
{ "name": "NouveauNom", "email": "new@mail.com" }DELETE http://localhost:8001/members/1
