You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I wasn't able to find an answer to this question in other issues, so here it is:
I am wondering if there is a standard or recommended way to have the default configuration for an environment loaded with config.load or config.loadFile if a config file is not found? Using part of the example config.js from the docs to illustrate,
varconvict=require('convict');// Define a schemavarconfig=convict({env: {doc: 'The application environment.',format: ['production','development','test'],default: 'development',env: 'NODE_ENV'},ip: {doc: 'The IP address to bind.',format: 'ipaddress',default: '127.0.0.1',env: 'IP_ADDRESS',},port: {doc: 'The port to bind.',format: 'port',default: 8080,env: 'PORT',arg: 'port'}});// Load environment dependent configurationvarenv=config.get('env');config.loadFile('./config/'+env+'.json');module.exports=config;
And say you have a development.json, test.json, and production.json.
Then you run your configuration with NODE_ENV=local. The script will fail with the error Cannot find module './config/local.json'.
Is there a way to have it use the default env setting development in this situation?
Quick aside. I know I can write my own "check if the file exists" function. I am wondering if there is already something built-in.
Thanks!
The text was updated successfully, but these errors were encountered:
jagretz
changed the title
Question: Is there a setting to allow fallback (default?) configuration if a
Question: Is there a setting to allow fallback (default?) configuration if a config file does not exist?
Oct 21, 2020
Hello, I wasn't able to find an answer to this question in other issues, so here it is:
I am wondering if there is a standard or recommended way to have the
default
configuration for an environment loaded withconfig.load
orconfig.loadFile
if a config file is not found? Using part of the exampleconfig.js
from the docs to illustrate,And say you have a
development.json
,test.json
, andproduction.json
.Then you run your configuration with
NODE_ENV=local
. The script will fail with the errorCannot find module './config/local.json'
.Is there a way to have it use the default env setting
development
in this situation?Quick aside. I know I can write my own "check if the file exists" function. I am wondering if there is already something built-in.
Thanks!
The text was updated successfully, but these errors were encountered: