1

Current code:

class Test { doOne = async () => { ... }; } module.exports = new Test(); 

I want something like this:

class Test { doOne = async () => { ... }; } const testOne = async () => { ... } module.exports = new Test(); 

How can I export testOne function? Is that possible to export both class Test and function testOne?

3
  • Just write exports.Test = Test; and exports.testOne = testOne;. Commented Aug 7, 2022 at 16:07
  • Btw, you should not export a new Test instance when you actually want to export the class. Or if you want to export an object, then you should not use class syntax, just create an object. Commented Aug 7, 2022 at 16:26
  • I need both class and function in same file. That function is used inside the class as well as some other files. So I want to make a stand-alone function for that part. Commented Aug 8, 2022 at 4:12

1 Answer 1

1

You need export an object with class and function properties.

class Test { doOne = async () => { ... }; } const testOne = async () => { ... } module.exports = { test: new Test(), testOne, }

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.