javascript - Update file referenced by require -


i have file (app.js) imports other js file (config.js) via require. imported file imports other files , on.

i able read data of imported file in app.js, want update values in imported file. values in config.js coming other imported files. tried update values in following way, not update them:

app.js

let config         = require ( 'config.js' ); config.db.user     = "newuser"; 

config.js

const dbconfig        = require ( './config-db' ); const assetsconfig    = require ( './config-assets' ); const smtpconfig      = require ( './config-smtp' );  module.exports = {     db              : dbconfig.db,     assets          : assetsconfig.assets,     smtp            : smtpconfig.email }; 

config-db.js

module.exports = {     db : {         user     : 'user',         password : '******',         server   : 'test-db.test.com',         database : 'testdb',         timezone : '+02:00'     } }; 

is there way can update values in config-db app.js?
require performs 2 way binding?

update:

after using setter value gets updated in running instance of app.js. value in file still remains same. , once restart app.js change lost, not want.

app.js

let config       = require ( 'config.js' ); config.db.update = "{'user': 'newuser'}"; 

config-db.js

module.exports = {     db : {         set update ( data ) { // jshint ignore:line             this.user = data.user;         },         user     : 'user',         password : '******',         server   : 'test-db.test.com',         database : 'testdb',         timezone : '+02:00'     } }; 

config.db.user = value 

config.db reference config-db.js module


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -