I have an application in KOA (framework of node js), my index load a configuration file and I would like load other different file when I check the application with my tests. How can I load different files in function of the environment?
You can define an environment variable.
You can use process.env.NODE_ENVor a custom one such as process.env.MY_ENV_VARIABLE
process.env.NODE_ENV
process.env.MY_ENV_VARIABLE
For example you can launch your KOA server for test with
NODE_ENV=test node index.js
Then load your config file :
const config = require(`${process.env.NODE_ENV}`.json);
You can define an environment variable.
You can use
process.env.NODE_ENV
or a custom one such asprocess.env.MY_ENV_VARIABLE
For example you can launch your KOA server for test with
Then load your config file :