From 29ce461e02fb5f408389b3ee91b86c7011b552ed Mon Sep 17 00:00:00 2001 From: Tal Ben-Ari Date: Mon, 17 Sep 2018 14:14:22 -0700 Subject: [PATCH] Remove instance of 'new require' anti-pattern Although it works correctly in Node.js, calling 'require' as a constructor is a discouraged and undocumented behavior, which may break in the future. Note that removing the 'new' keyword does not change functionality. --- app.js | 8 ++++---- authservice/routes/index.js | 4 ++-- routes/index.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app.js b/app.js index 38e071a..ffd8038 100644 --- a/app.js +++ b/app.js @@ -40,11 +40,11 @@ if (authServiceLocation) else authModule= authServiceLocation; - authService = new require('./'+authModule+'/index.js')(settings); + authService = require('./'+authModule+'/index.js')(settings); if (authService && "true"==process.env.enableHystrix) // wrap into command pattern { logger.info("Enabled Hystrix"); - authService = new require('./acmeaircmd/index.js')(authService, settings); + authService = require('./acmeaircmd/index.js')(authService, settings); } } @@ -62,8 +62,8 @@ if(process.env.VCAP_SERVICES){ } logger.info("db type=="+dbtype); -var routes = new require('./routes/index.js')(dbtype, authService,settings); -var loader = new require('./loader/loader.js')(routes, settings); +var routes = require('./routes/index.js')(dbtype, authService,settings); +var loader = require('./loader/loader.js')(routes, settings); // Setup express with 4.0.0 diff --git a/authservice/routes/index.js b/authservice/routes/index.js index f12073e..7626b59 100644 --- a/authservice/routes/index.js +++ b/authservice/routes/index.js @@ -24,7 +24,7 @@ module.exports = function (dbtype, settings) { var daModuleName = "../../dataaccess/"+dbtype+"/index.js"; logger.info("Use dataaccess:"+daModuleName); - var dataaccess = new require(daModuleName)(settings); + var dataaccess = require(daModuleName)(settings); module.dbNames = dataaccess.dbNames @@ -74,4 +74,4 @@ module.exports = function (dbtype, settings) { } return module; -} \ No newline at end of file +} diff --git a/routes/index.js b/routes/index.js index 17560bf..b58c42f 100644 --- a/routes/index.js +++ b/routes/index.js @@ -27,7 +27,7 @@ module.exports = function (dbtype, authService, settings) { var daModuleName = "../dataaccess/"+dbtype+"/index.js"; logger.info("Use dataaccess:"+daModuleName); - var dataaccess = new require(daModuleName)(settings); + var dataaccess = require(daModuleName)(settings); module.dbNames = dataaccess.dbNames