Making connections to 2 different Databases one a single app.

136 views
Skip to first unread message

Vrandesh Bandikatti

unread,
Nov 11, 2014, 7:32:14 AM11/11/14
to node-...@googlegroups.com
Hi,

I am trying to setup multiple connections on a app running nodejs, express, nodejs-mysql by felixge.
In my app.js when i try setting up two connections, it takes only the last one and does not use the first one during the runtime.

I have tried using poolCluster as a workaround, but this did not work. Need help on how i can get this done. Following is the code excerpt for setting up my connection:

var express = require('express');
var swig = require('swig');
var path = require('path');
var AWS = require('aws-sdk');
var connection  = require('express-myconnection');
//second connection
var myConnection = require('express-myconnection');
var mysql = require('mysql');
var app = express();
var session = require('express-session');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var passport = require('passport');
var localStrategy = require('passport-local').Strategy;

app
.use(
    connection
(mysql,{
        host
: 'localhost',
        user
: 'user1',
        password
: 'pass1',
        port
: 3306, //port mysql
        database
:'database1'
   
},'pool') //or single
);

app
.use(
    myConnection
(mysql,{
        host
: 'localhost',
        user
: 'user2',
        password
: 'pass2',
        port
: 3306, //port mysql
        database
:'database2'
   
},'pool') //or single
);



Reply all
Reply to author
Forward
0 new messages