I want to connect the databases which are for the different servers (like dev, staging, live, production). There are different databases and credential for all the server. When a server will be called it will access data only that particular database. In my code, I am using node js with sequelize for the database connection to build the API in GraphQL.How can I do this? I have already tried a lot. Please suggest to me. If need code I can post it here.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The best way to do this is to keep a seperate .env file on each server. and load the credentials form .env file itself by using dotenv module.
you can load credenials by process.env.CREDENTIALS_KEY
Example
DB_USERNAME=username
DB_PASSWPRD=password
DB_DATABASE=db_name
DB_HOST=localhost
Load in your js/ts file like:
"USERNAME": process.env.DB_USERNAME,
"PASSWORD": process.env.DB_PASSWPRD,
"DATABASE": process.env.DB_DATABASE,
"HOST": process.env.DB_HOST,