Yes, you can use multiple databases with your applications.
The easiest and most flexible way to do this is to declare multiple databases in the config.js and then loop over these databases in the file handling our database connections
module.exports = {
/**Declaration of databases for my development environment**/
"development": {
"databases": {
"Database1": {
"database": process.env.RDS_DATABASE1, //you should always save these values in environment variables
"username": process.env.RDS_USERNAME1, //only for testing purposes you can also define the values here
"password": process.env.RDS_PASSWORD1,
"host": process.env.RDS_HOSTNAME1,
"port": process.env.RDS_PORT1,
"dialect": "postgres" //here you need to define the dialect of your databse, in my case it is Postgres
},
"Database2": {
"database": process.env.RDS_DATABASE2,
"username": process.env.RDS_USERNAME2,
"password": process.env.RDS_PASSWORD2,
"host": process.env.RDS_HOSTNAME2,
"port": process.env.RDS_PORT2,
"dialect": "mssql" //second database can have a different dialect
},
},
}
}
You should user Sequelize that can be a good option to work with multiple-databases.
Here is the link where you can check how to add databases from scratch.
https://school.geekwall.in/p/H1gUJiuDN/how-to-using-multiple-database-in-nodejs
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…