I am trying to set up a connection between my WordPress database and my React Web Application. I am getting an error and I don't know how to fix it. Below is my code.
const express = require("express");
const app = express();
const mysql = require('mysql');
const connection = mysql.createConnection({
host : 'xxxxxx',
user : 'xxxxxx',
password: 'xxxxxx',
database: 'xxxxxx',
});
connection.connect((err) => {
if(err) throw err;
console.log('Connected to MySQL Server!');
});
app.get("/",(req,res) => {
connection.query('SELECT * from users LIMIT 1', (err, rows) => {
if(err) throw err;
console.log('The data from users table are: \n', rows);
connection.end();
});
});
app.listen(3000, () => {
console.log('Server is running at port 3000');
});
Error display in cmd:
Error: getaddrinfo ENOTFOUND xxxxx
...
...
...
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'xxxxx',
fatal: true