0

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.

Upasana
  • 45
  • 9

1 Answers1

0

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,
  • i have created a .env file. but here how could i define credential for each server? Could you explain to me through an example? – Upasana Apr 30 '19 at 05:49