Skip to content

Building a MySQL Database Connection with Node.js and Express

Notifications You must be signed in to change notification settings

DripCode-Studio/node-mysql-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build a REST API with Node.js, Express, and MySQL

Building a MySQL Database Connection with Node.js and Express

Setting up table and data

DBeaver Community is a free, open-source database management tool recommended for personal projects.

Parameters Connection for MySQL

Create a new connection

Parameters Connection for MySQL

Create the Database and Table

  • 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=8001

🎯 Test with Postman / Thunder Client / Insomnia

GET

GET http://localhost:8001/members

POST

POST http://localhost:8001/members

body JSON :

{ "name": "Ismael", "email": "test@example.com" }

PUT

PUT http://localhost:8001/members/1

{ "name": "NouveauNom", "email": "new@mail.com" }

DELETE

DELETE http://localhost:8001/members/1

About

Building a MySQL Database Connection with Node.js and Express

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published