How can I configure the .env file to be prepared for different connections, such as:
If I want production I go there in the .env file and change the DB_HOST = 185.565.55.5
If I want to test I go there in the .env file and change the DB_HOST = 192.168.1.0
If I want location I go there in the .env file and change the DB_HOST = localhost
How can I leave myself prepared for everything and only change one thing? For example:
Archive .env
#LOCAL
LOCAL_DB_HOST=localhost
LOCAL_DB_USER=root
LOCAL_DB_PASSWORD=123
LOCAL_DB_DATABASE=banco
#PRODUCAO
PROD_DB_HOST=185.565.55.5
PROD_DB_USER=root
PROD_DB_PASSWORD=senhaproducao
PROD_DB_DATABASE=banco
#TEST
TEST_DB_HOST=192.168.1.0
TEST_DB_USER=root
TEST_DB_PASSWORD=senha
TEST_DB_DATABASE=banco
And in the configuration I was trying like this:
/*
LOCAL = localhost
PROD = 5.5
TEST = 192
*/
const ambiente = 'LOCAL'+'_'
const HOST = ambiente+'DB_HOST'
const USER = ambiente+'DB_USER'
const pwd = ambiente+'DB_PASSWORD'
const db = ambiente+'DB_DATABASE'
const connection = mysqlServer.createConnection({
host : process.env.HOST,
user : process.env.USER,
password : process.env.pwd,
database : process.env.db
})
As I usually do in php, but it did not work. Ai in the variable ambiente
I just change to what I want.