0

I have a node module exported like this

module.exports = {
 port:8080,
 server:function(){
  console.log(port);
},
}

I want to read the port value ( and some other values as well) inside the server function but when I run my code it returns undefined.

How can I access other properties inside my server.

user3626708
  • 727
  • 2
  • 8
  • 24
  • 1
    `module.exports.port` or `this.port` as long as the `server` function is always called correctly (`var m = require('my-module'); m.server()` vs. passing `m.server` to some other function). – Mike Cluck Jun 17 '16 at 22:12
  • Yes, [refer to it as a property](http://stackoverflow.com/questions/10711064/javascript-object-literal-reference-in-own-keys-function-instead-of-this), not like a local variable – Bergi Jun 17 '16 at 22:57

0 Answers0