This project is a sample of handle MySQL to View, Insert, Update and Delete by using Express.js and Axios in React project.
Tutorial avaiable at https://hocwebchuan.com
Extract the download file.
Create and change your database information follow /app.js
file
host: 'localhost',
user: 'reactUser',
password: '1234567',
database: 'reactmysql'
Import /news.sql
file into your database system.
In the project directory, follow these steps:
Express is a module framework for Node that you can use for applications that are based on server that will listen for any input/connection requests from clients.
This project used Express to create App.
You can install Express.js by run:
npm install –save express
You need install node.js modules for this project:
cd client
npm install
Runs the app in the development mode:
npm start
Then you can see in the browser with the Welcome screen of React app.
Concurrently: support running multiple processes at the same time, this project we will run Port 3000 (client) and 4000 (server) at the same time.
npm install –save concurrently
Axios is a Javascript library used to make HTTP requests from node.js or XMLHttpRequests from the browser. We need to use Axios to get the data from server.
npm install –save axios
body-parser extract the entire body portion of an incoming request stream and exposes it on req.body.
npm install body-parser
react-modal, accessible modal dialog component for React.js
npm install react-modal
After install necessary libraries, now we can run the app by run this script at the root of project /React-server-and-client-master/
:
npm run dev
That's it!
After creation, your project should look like this:
React-server-and-client-master/
client/
node_modules/
public/
src/
App.js
.gitignore
package.json
package-lock.json
README.md
node_modules/
app.js
package.json
package-lock.json
README.md
If you have any problems, let me know.
Thanks for using it!