upadhya
upadhya

Reputation: 54

Is that possible to export Class and Function in the same file?

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?

Upvotes: 1

Views: 881

Answers (1)

Mina
Mina

Reputation: 17099

You need export an object with class and function properties.

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

const testOne = async () => {
  ...
}

module.exports = {
  test: new Test(),
  testOne,
}

Upvotes: 1

Related Questions