,

A Beginner’s Guide to Creating a CRUD Application with React, Node.js, and MySQL

Posted by






React Node.js MySQL CRUD Tutorial for Beginners

React Node.js MySQL CRUD Tutorial for Beginners

Introduction

In this tutorial, we will learn how to create a basic CRUD (Create, Read, Update, Delete) application using React, Node.js, and MySQL. This tutorial is targeted towards beginners who are new to these technologies.

Prerequisites

  • A basic understanding of HTML, CSS, and JavaScript
  • Node.js and npm installed on your machine
  • MySQL database setup

Step 1: Setting up the Project

First, let’s create a new directory for our project. Open your terminal or command prompt and run the following command:

mkdir react-node-mysql-crud-tutorial

Once the directory is created, navigate into it:

cd react-node-mysql-crud-tutorial

Next, initialize a new Node.js project:

npm init

Follow the prompts and enter the required information. This will generate a package.json file for our project.

Step 2: Setting up the Backend

Now, let’s install the required dependencies for our backend. Run the following command:

npm install express mysql body-parser

This will install Express, MySQL, and Body-parser packages.

In your project directory, create a new file called server.js. Open it and import the necessary modules:

const express = require('express');
    const mysql = require('mysql');
    const bodyParser = require('body-parser');

Next, set up the connection to your MySQL database:

const db = mysql.createConnection({
        host: 'localhost',
        user: 'your_username',
        password: 'your_password',
        database: 'your_database_name'
    });
    
    db.connect((err) => {
        if (err) {
            throw err;
        }
        console.log('Connected to the MySQL database');
    });

Initialize Express and configure the server:

const app = express();
    const port = 3000;

Step 3: Setting up the Frontend

In your project directory, create another directory called client:

mkdir client

Navigate into the client directory:

cd client

Create a new React app:

npx create-react-app .

This will create a new React app inside the client directory.

Step 4: Creating the UI

Open the src/App.js file in the client directory and replace its contents with the following code:

import React from 'react';
    
    function App() {
        return (
            

React Node.js MySQL CRUD Tutorial

); } export default App;

Conclusion

In this tutorial, we have set up the basic structure for our React Node.js MySQL CRUD application. We have created the project directory, set up the backend with Express and MySQL, and created the frontend with React. In the next steps, we will implement the CRUD operations and connect the frontend with the backend to complete the application.

Stay tuned for the next part of this tutorial where we will continue building the application!


0 0 votes
Article Rating
20 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Profazia
1 year ago

How To Deploy It ?

Alese Brave
1 year ago

What difference React Node.js have from React?

TK OT7
1 year ago

heeeere we gooooo
8:00

lori bryant499
1 year ago

Hey can you create an api video an in depth one with nodejs and mysql. I really love you tutorials. This time I want to learn how to use sequalize in creating an api

Bình Đặng
1 year ago

video good

Bình Đặng
1 year ago

good video

Totalement Food
1 year ago

thank you for your tuto, I have a question :
If I want the fields on my update page to already contain the object to be modified, how should I code the update.jsx page?
What's more, I'd like to be able to modify just one field if necessary, without having to re-enter everything.
Thanks again for your time

Avie Grinberg
1 year ago

Your videos are so informative with concise tools and styling techniques, thank you!

22CSC08 Gowtham
1 year ago

Getting 404 error can anyone help me?…

DoomC
1 year ago

If you get {"code":"PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR","fatal":false} type this: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password_here'; into the MYSQL workbench file –> new query tab and click the middle lightning bolt. Then restart your node server.

Muhammad Paracha
1 year ago

45:07 For those who don't like using "useLocation()" You can always use "useParams()" as a quick alternative

First just make sure you have declared in "App.js"
<Route path='/update/:editingId' Component={Update}></Route>

The params is called "editingId"

Then call it in "Update.js"
const {editingId} = useParams()

This will just give everything after the "/update/"
lmk if you have any improvements/ suggestions

Kevin Philip
1 year ago

for those that are getting the authentican error, run the command he put at 12:46 on mySQL workbench and the password being the actual password. Make sure the password is the same in index.js aswell and then run the code

Misael V
1 year ago

thank you for this video, i am actually having fun! 🙂

Mahmoud Khalid
1 year ago

Good video, where is docs that I can find query of SQL to write in the code.
Shouldn't you use library like multer to upload your images ?

Maxi
1 year ago

How does this delete thing work for you?

Backend index.js ->

app.delete('/book/:id', (req, res) => {…

Here is /book/:id

Client Books.jsx ->

const handleDelete = async (id) => {

try {

await axios.delete(`http://localhost:8800/books/${id}`);

Here is /books/:id

TuzgBach
1 year ago

Hello everyone, I have a problem in uploading the product's image, can anyone guide me?

Just Cos
1 year ago

Npx create react-app keeps showing me ' npm ERR! could not determine executable

Shaun Rowley
1 year ago

really good video, i would have loved you to show how you would allow the user to select the book image when adding a book and how this is stored in the database and reused on the app? im really struggling with that

Ramon Iroomo
1 year ago

make sure you have the same plugins as him because if you follow his exact steps you will only get errors

Rahul Pandey
1 year ago

Ecommerce application in fullstack