Im trying to connect nodejs to mysql running from lando.. db is up and running...
any other non nodejs project (non node js) i can connect without issues
does anyone have an idea why this might happen? am i missing something?
My nodejs connection
const express = require('express');
const app = express();
const cors = require('cors');
const mysql = require('mysql');
app.use(cors());
const db = mysql.createConnection({
host: 'database',
user: 'lemp',
password: 'lemp',
database: 'lemp',
port: 3306
});
my lando config:
services:
database:
type: mysql
creds:
username: lemp
password: lemp
my DB from terminal
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| lemp |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> use lemp
Database changed
output
$ node index.js
Server listening on port 8080
/home/maarten/www/react/test/server/index.js:19
if (err) throw err;
^
Error: getaddrinfo EAI_AGAIN database
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)
--------------------
at Protocol._enqueue (/home/maarten/www/react/test/server/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/home/maarten/www/react/test/server/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/home/maarten/www/react/test/server/node_modules/mysql/lib/Connection.js:116:18)
at Object.<anonymous> (/home/maarten/www/react/test/server/index.js:18:4)
at Module._compile (node:internal/modules/cjs/loader:1356:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
at Module.load (node:internal/modules/cjs/loader:1197:32)
at Module._load (node:internal/modules/cjs/loader:1013:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
at node:internal/main/run_main_module:28:49 {
errno: -3001,
code: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'database',
fatal: true
}
Node.js v18.19.0
❯ node -v v18.19.0 ❯ npm -v 10.2.3
tried internal and localhost as mysql host in nodejs but does noet work