開発環境
参考動画
使用したパッケージ
バックエンド
terminal
npm install body-parser cors dotenv express mysql2 nodemon
フロントエンド
terminal
npm install axios react-router-dom react-toastify
完成品
MySQLと接続
index.js
const mysql = require("mysql2");
const db = mysql.createPool({
host: process.env.HOST,
user: "root",
password: "",
database: "crud_contact",
});
Axios 全データの取得
Home.jsx
const [data, setData] = useState([]);
const loadData = async () => {
const response = await axios.get("http://localhost:5000/api/get");
setData(response.data);
};
参考資料