Question: I am curious about how to access another object property in module.exports.

**here is the case :**

```js
module.exports = {

    text: 'abcd',
    index: (req, res)=>{
    console.log(text) <-- is not defined
    console.log(this.text) <-- undefined
    }
}
```

> 
> well then, how to access the text property? thanks guys need your explanation.
> 
> 
>

Answer: 
Javascript does not have a built-in way to refer to other properties in the same object. There are good reasons why it cannot do this for any arbitrary property. So, you either have to make sure that `this` has the right object value in it or you need to save the appropriate object reference yourself somewhere that you can get to it.

Here's a way where you save the object reference yourself which works fine for a singleton object:

```
let myObj = {

 text: 'abcd',
 index: (req, res)=>{
   console.log(myObj.text)
 }

}

module.exports = myObj;

```

---

If you know that `.index()` will always be called appropriately as a method on your `module.exports` (which would be the usual case), then you can stop using the `=>` definition and use a normal `function` definition (which should pretty much always be used for method declarations) and then `this` will have the desired value.

```
module.exports = {

 text: 'abcd',
 index: function(req, res) {
   console.log(this.text)
 }
}

```

This will work as long as `.index()` index is called like this:

```
let myModule = require('myModule');
myModule.index(req, res);

```

People tend to fall in love with the arrow syntax and forget that it should pretty much NEVER be used for method definitions because it does NOT set `this` to the host object which creates problems for methods. Instead, use the regular `function` definition for methods of an object.

---

Arrow functions are typically very useful for callback functions where you want the callback to have access to the `this` value from your environment (called the lexical value of `this`). Here are some useful examples:

```
class Timer {
    delay(t, cb) {
       this.timer = setTimeout(() => {
           // preserve this value inside a callback
           this.timer = null;
           cb();
       })
    }
}

```

Or

```
// preserve this value inside a callback
let filtered = myArray.filter(item => {
    return item.id !== this.master.id;
});

```

---

On the other hand, you pretty much never want to use an arrow declaration for a method because that will override the usual object value for `this` and replace it with a lexical value for `this`.
Try this 

```
module.exports = {

        text: 'abcd',
        index: function (req,res) {
            console.log(this.text)
        }
    }

```

accessing via

```
var te=require('modulename')
    te.index()

```