0

I made a nice folder structure with the use of require and require in require in javascript. As the require in require needs all functions to be included again I was wondering if there are easier ways to do this.

var file2 = require('./file2.js');

var IncludeAll={
        func1: function(msg){
            return file2.function1(msg);
        },
        func2: function(msg){
            return file2.function2(msg);
        }
};

module.exports = IncludeAll;
1
  • I don't see any nested requires. What do you mean? Commented Nov 14, 2019 at 14:17

1 Answer 1

1

You can create a exporter script "exporter.js" file like below.

// exporter.js
module.exports = {
   File2: require('./file2'),
   File3: require('./file3')
}

Then you can import and call like this.

const {File2} = require('./exporter')
const param = 5;
File2.func1(param);
File2.func2(param);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.