I
I
Ivan2017-08-06 19:47:16
Node.js
Ivan, 2017-08-06 19:47:16

Module.exports how to access a property inside a module?

A small application is made like this.
1. main.js in which it is connected 2. In add.js
var main = require('./add.js')

module.exports = {
  
    prop1: function () { .......}
    prop2: function () { .......}
    prop3: function () { .......}
}

is it possible to somehow call prop3 as a function in the prop1 code?
those. main.prop1( working... calling prop3..).

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
Coder321, 2017-08-07
@Iv_and_S

const myObj = {
    prop1: function () { .......}
    prop2: function () { .......}
    prop3: function () { myObj.prop1() }
}
module.exports = myObj

S
Sergey Sergey, 2017-08-06
@hahenty

Define a module property as a variable inside the module -- it will be possible to access it from anywhere in the module.
Associate a property with a variable.

E
emp1re, 2017-08-07
@emp1re

You write your methods to the exports object.
Refer to it -> exports.prop3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question