Example, you have an app, you would like to have a configuration override for user A and another for user B.
The idea is to link a file (usually env.json
) to the configuration loading to extend/override the configuration.
application.ts :
const conf = {
url: 'http://an-url.com',
};
export default conf;
to override is locally you can add a development.ts
or local.ts
const conf = {
url: 'http://a-local-url.lan',
};
export default conf;
to override it for user a, create a file env.json
or env.yaml
:
env.json
: (remove comments)
{
application: {
// choose which environment you want to override, you can overide all with one file
'app-name': {
// your application name, so you can share this env.json for all your apis for instance
url: 'http://user-a.com',
},
},
}
env.yaml
:
application: # choose which environment you want to override, you can overide all with one file
app-name: # your application name, so you can share this env.json for all your apis for instance
url: http://user-a.com
- in integration for instance :
url === http://user-a.com
fromenv.json
- in development : url is
http://a-local-url.lan
fromdevelopment.ts
orlocal.ts
which are loaded overapplication.ts
import n9NodeConf from '@neo9/n9-node-conf';
import { join } from 'path';
const conf = n9NodeConf({
path: join(__dirname, 'conf'),
extendConfig: {
path: {
relative: './conf/env.json',
},
},
});