• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion
  • Inviting everyone to the UX test of a new security feature in the WP Toolkit
    For WordPress site owners, threats posed by hackers are ever-present. Because of this, we are developing a new security feature for the WP Toolkit. If the topic of WordPress website security is relevant to you, we would be grateful if you could share your experience and help us test the usability of this feature. We invite you to join us for a 1-hour online session via Google Meet. Select a convenient meeting time with our friendly UX staff here.

Issue NodeJS cannot connect to MySQL database on same server

steve53

New Pleskian
Hi everyone,

I am running the latest Plesk on a Ubuntu server.

I have a domain (domain.com) and a subdomain called api.domain.com

I have installed a nodejs application for the api.domain.com via the interface and it is running and will return sample route return data as long as it is not querying the database.

I have installed a database under domain.com and it shows api.domain.com on the interface to the side where it says add-on domains also.

I have tried connecting to this database from my local machine and also from the node application but it will not work locally and I assume it will not work from the node application either.

I checked var/log/apache2/logs/error.log and it does not seem to throw an error for the initial connection in the start of the nodejs app:

const connection = mysql.createConnection({
host: 'localhost',
user: 'admin',
password: 'secretpassword',
database: 'app',
});

connection.connect(err => {
if (err) throw err;
console.log('Connected!');
});

because in the error.log it does show the Connected! so it seems to have a connection?

But in my test route nothing is shown except: 'Cannot GET /people/1' on the browser
I also have 2 different rows added with data in the people table within the app database.

app.get('people/:id', (req, res) => {

console.log('Fetching data with id' + req.params.id);
const id = req.params.id;
const queryString = "SELECT * FROM people WHERE id = ?";

connection.query(queryString, [id], (err, rows, fields) =>
{
console.log('I think we fetched'); // this does not show
res.json(rows);
});

});

In the database management for the user it is set to Allow remote connections from any host

From the firewall screen it seems to allow all incoming connections:
FTP server passive ports Allow incoming from all
rule-allow.png
Customer & Business Manager payment gateways Allow incoming from all
rule-allow.png
Single Sign-On Allow incoming from all
rule-allow.png
Plesk Installer Allow incoming from all
rule-allow.png
Plesk administrative interface Allow incoming from all
rule-allow.png
WWW server Allow incoming from all
rule-allow.png
FTP server Allow incoming from all
rule-allow.png
SSH (secure shell) server Allow incoming from all
rule-allow.png
SMTP (submission port) server Allow incoming from all
rule-allow.png
SMTP (mail sending) server Allow incoming from all
rule-allow.png
POP3 (mail retrieval) server Allow incoming from all
rule-allow.png
IMAP (mail retrieval) server Allow incoming from all
rule-allow.png
Mail password change service Allow incoming from all
rule-allow.png
MySQL server Allow incoming from all
rule-allow.png
PostgreSQL server Allow incoming from all
rule-allow.png
Samba (file sharing in Windows networks) Allow incoming from all
rule-allow.png
Plesk VPN Allow incoming from all
rule-allow.png
Domain name server Allow incoming from all
rule-allow.png
IPv6 Neighbor Discovery Allow incoming from all
rule-allow.png
Ping service Allow incoming from all



Hoping some of you can help me out with this headache, thanks!
 
Back
Top