Maciej Sobala Maciej Sobala - 1 month ago 6
Node.js Question

Creating node module with subfolders

I am developing npm module. I have following index.ts

export * from './src/A/index';


At this moment, in app import statement looks as follow:

import {something} from 'myModule';


I would like to add some extra logic to my module, and organize it like:

export * from './src/A/index';
export * from './src/B/index';
export * from './src/C/index';


What should I write in index.ts to make my module to be used in this way:

import {something} from 'myModule/A'
import {something2} from 'myModule/B'


etc.?

Answer

What should I write in index.ts to make my module to be used in this way

Given that you want to use import {something} from 'myModule/A' implies that myModule/A folder should have an index.ts that exports something.

This conflicts with the fact that A/index is actually located in myModule/src/A/index.

Move the file and it should work.