javascript - How to reference a Node.js module's context object from inside that module? -


is possible reference module's context object inside module itself? not global object or exports object, private context object of module...

for example inside node.js module i'm looking way this:

var = 1; var b = 2;  // context reference i'm looking console.log(context); // -> {a: 1, b: 2} 

the context of module (vars, module , exports) available in module. if in module , require script:

var _pv = 1;  var _foo = function() {     console.log('foo'); } exports.foo = _foo;  console.log('pv: ' + _pv); _foo();  console.log(module); console.log(module.exports); 

it outputs:

pv: 1 foo { id: '/users/bryanmac/testing/test2/mod.js',   exports: { foo: [function] },   parent:     { id: '.',      exports: {},      parent: null,      filename: '/users/bryanmac/testing/test2/test.js',      loaded: false,      children: [ [circular] ],      paths:        [ '/users/bryanmac/testing/test2/node_modules',         '/users/bryanmac/testing/node_modules',         '/users/bryanmac/node_modules',         '/users/node_modules',         '/node_modules' ] },   filename: '/users/bryanmac/testing/test2/mod.js',   loaded: false,   children: [],   paths:     [ '/users/bryanmac/testing/test2/node_modules',      '/users/bryanmac/testing/node_modules',      '/users/bryanmac/node_modules',      '/users/node_modules',      '/node_modules' ] } { foo: [function] } 

edit:

you clarified it's vars in current scope. don't believe can variables technically. see: getting variables in scope

but can export variable , available on module , module.exports pointed out above.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -