I am using node-pg-migrate and would like the db name, password and schema to come from the .env file as opposed to a config file. The .env file is not being used as using the default database. Could you let me know how to get the .env file to be used?
The app uses TypeScript.
NPM script block
"scripts": {
"migrate": "ts-node node_modules/.bin/node-pg-migrate -j ts -m src/migrations",
"start:build": "tsc -w",
"start:run": "nodemon -r dotenv/config build/index.js",
"start": "concurrently npm:start:*"
}
The .env is stored in the root of the project and uses the settings:
POSTGRES_PORT=5432
POSTGRES_DB='testdb'
POSTGRES_PASSWORD='somePass'
POSTGRES_USER='anon'
POSTGRES_SCHEMA='sch'
The settings values work fine when reading from the default.json
Versions used: "typescript": "^4.2.4" "node-pg-migrate": "^5.9.0" "dotenv": "^8.2.0" Node 14.16.0
Many thanks
Configuration data must be saved in DATABASE_URL or you can change the standard source:
Taken from the documentation:
You can adjust defaults by passing arguments to node-pg-migrate: database-url-var (d) - Name of env variable with database url string (defaults to DATABASE_URL)