2

What is the approach to import all the modules from the given folder?

I've read in excellent basarat's "Beginning node.js" book that I can create index file in the folder and make all imports in it.

As an example my index.ts file (located in "common" folder):

import * as moduleA from './moduleA';
import * as moduleB from './moduleB';

And an example of my app.ts file:

import * as common from './common/index';

But this approach doesn't work. What is wrong with my code?

1 Answer 1

3

Right now the files are only being imported into index.ts, but they are not being exported.

To fix this, you can change the import statements to export statements:

export * from './moduleA';
export * from './moduleB';
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I didn't know there is an export instead of import option. Now it works.
There are really not any plugins or any other options? Just this making an index file in a nobrainer manner?

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.