2

This is my configuration file of my API connections

const mysql = require("mysql");

const pool = mysql.createPool({
  connectionLimit: 10,
  user: user1,
  password: 123456,
  database: database1,
  host: host1.server.com,
  port: 3306,
});

exports.pool = pool;

What I need is for my API to connect to more than one server, where the databases are. How can be?

I tried it like this and it didn't work:

const mysql = require("mysql");

const pool1 = mysql.createPool({
  connectionLimit: 10,
  user: user1,
  password: 123456,
  database: database1,
  host: host1.server.com,
  port: 3306,
});

const pool2 = mysql.createPool({
  connectionLimit: 10,
  user: user2,
  password: 123456,
  database: database2,
  host: host2.server.com,
  port: 3306,
});

exports.pool = { pool1, pool2};

Can someone help me?

4
  • What didn't work about it? Commented Dec 30, 2021 at 0:35
  • 1
    Check out this post. I believe it may have something to do with connections vs pools. Commented Dec 30, 2021 at 0:38
  • This post is about connections, I would like it to be in a Pool. Commented Dec 30, 2021 at 0:42
  • 1
    Yes, but perhaps pools are the problem. Why not try it with a regular connection and debug from there? Commented Dec 30, 2021 at 1:02

1 Answer 1

1

I solved the problem.

I wasn't exporting correctly. Then I fixed it as below, and it worked.

module.exports = { pool, pool2 };

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.