Load different files depends of environment

227 views Asked by At

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?

1

There are 1 answers

0
MatthieuLemoine On

You can define an environment variable.

You can use process.env.NODE_ENVor a custom one such as 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);