javascript - Error properties not defined when pointing to a local variable -


i have following configuration file :

/* env.js */  env_to_use = [ "local" ];  // local; dev; rec; pre; prod module.exports = {     env_properties : {         local : {             root_url : "localhost",             port : 3000,             root_dir : "/home/user/project/"         },         dev : {             root_url : "devdomain",             port : 3000,             root_dir : "/apps/project/",         }     },     global_properties : {         path_include :         {             path_express : env_properties[env_to_use].root_dir + 'express'         }     } }; 

and in file, want print 'path_express' value :

/* test.js */  var env = require('./env.js'); console.log(env.global_properties.path_include.path_express); 

but when launch script command node test.js, following error :

path_express : env_properties[env_to_use].root_dir + 'express'                        ^ referenceerror: env_properties not defined @ object.<anonymous> (c:\cygwin64\home\user\project\env.js:23:21) @ module._compile (module.js:413:34) @ object.module._extensions..js (module.js:422:10) @ module.load (module.js:357:32) @ function.module._load (module.js:314:12) @ module.require (module.js:367:17) @ require (internal/module.js:16:19) @ object.<anonymous> (c:\cygwin64\home\user\project\test.js:1:73) @ module._compile (module.js:413:34) @ object.module._extensions..js (module.js:422:10) 

i still want keep 1 single file, , not creating second file. how can solve problem ?

/* env.js */ env_to_use = [ "local" ];  var env_properties = {         local : {             root_url : "localhost",             port : 3000,             root_dir : "/home/user/project/"         },         dev : {             root_url : "devdomain",             port : 3000,             root_dir : "/apps/project/",         }     }  // local; dev; rec; pre; prod module.exports = {     env_properties : env_properties,     global_properties : {         path_include :         {             // , have specify env want use             path_express : env_properties[0].root_dir + 'express'         }     } }; /* no need export env_properties since included in scope */ 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -