In this tutorial, I will show you how to build full-stack React + Node.js + Express + MySQL example with a CRUD Application. The back-end server uses Node.js + Express for REST APIs, front-end side is a React.js client with React Router, Axios & Bootstrap.
React + Node.js + Express + MySQL example Overview
We will build a full-stack Tutorial Application in that:
- Tutorial has id, title, description, published status.
- User can create, retrieve, update, delete Tutorials.
- There is a search box for finding Tutorials by title.
Here are screenshots of the example.
– Add an item:
– Show all items:
– Click on Edit button to view details of an item:
On this Page, you can:
- change status to Published/Pending using Publish/UnPublished button
- remove the object from MySQL Database using Delete button
- update this object’s details on Database with Update button
– Search objects by field ‘title’:
– Check MySQL database:
React, Node.js Express, MySQL Architecture
We’re gonna build the application with following architecture:
– Node.js Express exports REST APIs & interacts with MySQL Database using Sequelize ORM.
– React Client sends HTTP Requests and retrieves HTTP Responses using Axios, consume data on the components. React Router is used for navigating to pages.
This is our React Node.js Express Sequelize application demo (with brief instruction) running with MySQL database.
Node.js Express Back-end
These are APIs that Node.js Express App will export:
|GET||api/tutorials||get all Tutorials|
|GET||api/tutorials/:id||get Tutorial by |
|POST||api/tutorials||add new Tutorial|
|PUT||api/tutorials/:id||update Tutorial by |
|DELETE||api/tutorials/:id||remove Tutorial by |
|DELETE||api/tutorials||remove all Tutorials|
|GET||api/tutorials?title=[kw]||find all Tutorials which title contains |
– db.config.js exports configuring parameters for MySQL connection & Sequelize.
– Express web server in server.js where we configure CORS, initialize & run Express REST APIs.
– Next, we add configuration for MySQL database in models/index.js, create Sequelize data model in models/tutorial.model.js.
– Tutorial controller in controllers.
– Routes for handling all CRUD operations (including custom finder) in tutorial.routes.js.
You can find step by step to implement this Node.js Express App in the post:
Node.js Rest APIs example with Express, Sequelize & MySQL
App component is a container with React
Router. It has
navbar that links to routes paths.
TutorialsList component gets and displays Tutorials.
Tutorial component has form for editing Tutorial’s details based on
AddTutorial component has form for submission new Tutorial.
– These Components call
TutorialDataService methods which use
axios to make HTTP requests and receive responses.
- React 16
- react-router-dom 5.1.2
- axios 0.19.2
- bootstrap 4.4.1
– package.json contains 4 main modules:
App is the container that has
Router & navbar.
– There are 3 components:
– http-common.js initializes axios with HTTP base Url and headers.
TutorialDataService has methods for sending HTTP requests to the Apis.
– .env configures port for this React CRUD App.
Today we have an overview of React.js + Node.js Express + MySQL example when building a full-stack CRUD App.
We also take a look at client-server architecture for REST API using Express & Sequelize ORM, as well as React.js project structure for building a front-end app to make HTTP requests and consume responses.
Next tutorials show you more details about how to implement the system (including source code):
React Pagination with API using Material-UI
Happy learning, see you again!