0

I am using a particular set of URLs for connecting to services. They are there in the config.js file. Now while testing using mocha, I want to use a different set of urls. Is it possible to over-ride the urls configured in the js file from the test cases.This is how my config.js looks -

var servercfg = {
  host: 'localhost',
  port: '9010'
};

var enterprisesercfg = {
  userserurl: 'http://localhost:9020',
  accountserurl: 'http://localhost:9020',
  creditcardserurl: 'http://localhost:9020'
};

var oauth2sercfg = {
  url: 'http://localhost:9000/api/oauth2/verify'
};

module.exports={
  servercfg,
  enterprisesercfg,
  oauth2sercfg
};
user3276247
  • 1,046
  • 2
  • 9
  • 24
  • urls configured in the js file from the test cases ? does it mean you want separate urls based on environment or something else ? – Saroj Feb 21 '18 at 14:08
  • ya separate urls for different environments – user3276247 Feb 22 '18 at 19:17
  • There are several libraries available for achieving this like https://www.npmjs.com/package/config . I think the OP has answered with a n example to a library, You can find more info about config.js here https://medium.com/@fedorHK/no-config-b3f1171eecd5 – Saroj Feb 23 '18 at 07:58

1 Answers1

0

There are already several solutions to manage your configuration; for example this one: https://github.com/lorenwest/node-config You define different files for your different NODE_ENV.

//development.json
{
  "someURL": "http://url.com"
}

//test.json
{
  "someURL: "http://url.com"
}

So all you need to do to change the file from which you load the config is set the NODE_ENV variable when starting your app.

There are other modules besides this one, it's just an example on how to solve your problem.

yBrodsky
  • 4,981
  • 3
  • 20
  • 31