Jeanluca Scaljeri
Jeanluca Scaljeri

Reputation: 29109

How to make libs available in node module

Assume a project B which depends on a node module A. A looks like this:

./node_modules/A
    ./src
        ./shared
            bar.js
            foo.js
    .... etc ....

In B I would like to use bar.js and foo.js I can import these now as follows

import Bar from './node_modules/A/src/shared/bar';
import Bar from './node_modules/A/src/shared/bar';

Now the question is, is there a way such that I can do

import Bar from 'bar';   
import Foo from 'foo';

Is this possible ? Because I own module A, its no problem if this required changes to A!

Upvotes: 0

Views: 30

Answers (1)

Derick Bailey
Derick Bailey

Reputation: 72858

you could use the NODE_PATH environment variable to tell node which paths to include when you do an import.

but this seems like a bad idea, off-hand.

if you need foo and bar available in both A and B, then they should be put into a new module on their own... module C.

then A and B can both import C

Upvotes: 1

Related Questions