'I am trying to connect and read data from mysql in node js and react project with clinet and server setup but

**I am trying to connect and read data from MySQL database in node js and react project with client and server setup but unable to get success, here is the code, thanks to all those who can help me, I am a new learner

this is index.js source code for server-side**

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

const app = express();
const mysql = require('mysql');

const db = mysql.createPool({
   host: 'localhost',
   user: 'root',
   password: '3Nbnv21PP',
   database: 'cpdb',
});

app.use(cors());
app.use(express.json);
app.use(bodyParser.urlencoded({ extended: true }));

app.get('/api/fetch', (req, res) => {
  const sqlSelect = 'SELECT * FROM cpdb.schools';
  db.query(sqlSelect, (err, result) => { res.send(result); });
});
app.listen(3001, () => {
  console.log('Running on port 3001');
});

on server-side I am getting this error : (index):6772 crbug/1173575, non-JS module files deprecated.

this is the app.js source code for client-side

import React, { useEffect, useState } from 'react'
import axios from 'axios'
import './App.css'

function App () {
  const [schlist, setschlist] = useState([])
  useEffect(() => {
    axios.get('http://localhost:3001/api/fetch').then((response) => {
      setschlist(response.data)
    })
  }, [])

  return (
    <div className='App'>
      <h1>HEllO</h1>
      
      {schlist.map((val, index) => {
        return <h1 key={index.id}> Sch: {val.schoolName} | Stu: {val.toatlStudents} | TTeach: {val.totalTeachers} | TFees: {val.TotalFeesCollected} </h1>
      })}
    </div>
  )
}
export default App

on client-side I am getting this

click on this image to see console

Here is the link to my GitHub repository

https://github.com/CodePex/db-test.git



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source