Skip to content

Error: getaddrinfo ENOTFOUND when trying to connect to WordPress database with correct credentials #2489

@ecsmagic16

Description

@ecsmagic16

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions