Dani-Br Dani-Br - 3 months ago 27
MySQL Question

connect nodeJS to MySQL when computer is offline

When the computer is offline, then my Electron app can't connect to the local MySQL.

When the computer connected to the internet, everything works fine.

Tested on Windows only.

The same happens in nodeJS (command prompt) and in Electron.

code:

s = {database: "test", user: "test", password: "test", host: "localhost"}
var mysql = require('./mysql');
var mysqlc = mysql.createConnection(settings);
mysqlc.connect(function(err) { console.log(err); });


The error code is:

{ [Error: getaddrinfo ENOENT localhost:3306]
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'getaddrinfo',
hostname: 'localhost',
host: 'localhost',
port: 3306,
fatal: true }


Why ?

What can I do about it ?

Answer

Try using:

s = {database: "test", user: "test", password: "test", host: "127.0.0.1"}
var mysql = require('./mysql');
var mysqlc = mysql.createConnection(settings);
mysqlc.connect(function(err) { console.log(err); });