Search code examples
mysqlnode.jsexpressionos

1and1 IONOS Database with Node.JS


I would like to connect my 1and1 mySQL Database on an Express App Node.JS with the mysql npm package but when I tried to connect the console send me back this:

Error: getaddrinfo ENOTFOUND <DB_HOST_NAME>

I looked on the 1and1 dashboard and it was the good logs, I tried to put 'tcp:\\' and ':3306' but no results, node can't find the database. Moreover the first website version was in PHP and the logs was working and still working with PHP so the logs are correct. I asked the 1and1 service but no answer.

I looked for survey on this error but anybody was able to find an answer.

Few snippets:

// Import Modules
const EXPRESS = require('express');
const CORS = require('cors');
const MYSQL = require('mysql');

// Import Database Configuration
const DB_CONFIG = require('./config/DbConfiguration');

// Create Express App Instance
const APP = EXPRESS()
APP.use(CORS())

// Server Port Const
const SERVER_PORT = 4000

// Create MySQL Connection Instance
const CONNECTION = MYSQL.createConnection(DB_CONFIG.dbConfiguration);
CONNECTION.connect(function(err) {

    // Print Error 
    if(err) {console.error(err)};

});

DbConfiguration.js

require('dotenv/config')

module.exports = {

    dbConfiguration: {
        host: process.env.DB_HOST,
        user: process.env.DB_USER,
        password: process.env.DB_PASSWORD,
        database: process.env.DB_NAME
    }
}

.ENV file

DB_HOST=xxxxx.1and1.fr
DB_USER=xxxxxxx  
DB_PASSWORD=xxxxxx
DB_NAME=xxxxxxx  

Solution

  • Have been looking at this problem myself recently too. Due to the way in which 1&1 IONOS manage security to their mySQL servers, you're only able to connect to them using your account (workspace). Further information on this is accessible via their website. Unfortunately, you either need to deploy your code to your workspace or use an alternative local phpMyAdmin installation for development. Not ideal I know!